Part Number Hot Search : 
VZ0603 000MH 70EPF08 TLP74 XE0101 10050 SI7448DP BU941ZT
Product Description
Full Text Search
 

To Download MC9S08RG60 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  hcs08 microcontrollers freescale.com mc9s08rc8/16/32/60 mc9s08rd8/16/32/60 mc9s08re8/16/32/60 mc9s08rg32/60 data sheet MC9S08RG60/d rev 1.10 08/2004

MC9S08RG60 data sheet covers: mc9s08rc8/16/32/60 mc9s08rd8/16/32/60 mc9s08re8/16/32/60 mc9s08rg32/60 MC9S08RG60/d rev 1.10 08/2004
revision history to provide the most up-to-date information, the revision of our documents on the world wide web will be the most current. your printed copy may be an earlier revision. to verify you have the latest information available, refer to: http://freescale.com the following revision history table summarizes changes contained in this document. version number revision date description of changes 1.07 2/4/2004 initial external release. 1.08 4/22/2004 changes to table c-6 in electricals section. 1.09 7/7/2004 added table c-4; changes to table c-6; changed to freescale format 1.10 8/11/2004 removed brk bit 13 and txinv, which are not available on this module version; ?ed typo in figure 13-2; corrected the sptef description in section 12.3 this product contains superflash ? technology licensed from sst. freescale and the freescale logo are trademarks of freescale semiconductor, inc. freescale semiconductor, inc., 2004. all rights reserved.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 5 mc9s08rc/rd/re/rg list of chapters chapter 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 chapter 2 pins and connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 chapter 3 modes of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 chapter 4 memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 chapter 5 resets, interrupts, and system configuration . . . . . . . . . . . . . . . 57 chapter 6 central processor unit (cpu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 chapter 7 carrier modulator timer (cmt) module . . . . . . . . . . . . . . . . . . . . . 93 chapter 8 parallel input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 chapter 9 keyboard interrupt (kbi) module . . . . . . . . . . . . . . . . . . . . . . . . . 121 chapter 10 timer/pwm module (tpm) module . . . . . . . . . . . . . . . . . . . . . . . 127 chapter 11 serial communications interface (sci) module . . . . . . . . . . . . 143 chapter 12 serial peripheral interface (spi) module . . . . . . . . . . . . . . . . . . 161 chapter 13 analog comparator (acmp) module . . . . . . . . . . . . . . . . . . . . . 177 chapter 14 development support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 appendix c electrical characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 appendix d ordering information and mechanical drawings . . . . . . . . . . 223
list of chapters mc9s08rc/rd/re/rg 6 freescale semiconductor
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 7 mc9s08rc/rd/re/rg contents chapter 1 introduction 1.1 overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 5 1.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 5 1.2.1 standard features of the hcs08 family . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.2.2 features of mc9s08rc/rd/re/rg series of mcus . . . . . . . . . . . . . . . . . . . . . 15 1.2.3 devices in the mc9s08rc/rd/re/rg series. . . . . . . . . . . . . . . . . . . . . . . . . . . 16 1.3 mcu block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.4 system clock distribution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 chapter 2 pins and connections 2.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 9 2.2 device pin assignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.3 recommended system connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.3.1 power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.3.2 oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.3.3 ptd1/ reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.3.4 background/mode select (ptd0/bkgd/ms). . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.3.5 iro pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.3.6 general-purpose i/o and peripheral ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.3.7 signal properties summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 chapter 3 modes of operation 3.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 9 3.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 9 3.3 run mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.4 active background mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.5 wait mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.6 stop modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.6.1 stop1 mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.6.2 stop2 mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.6.3 stop3 mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.6.4 active bdm enabled in stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.6.5 lvd reset enabled in stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.6.6 on-chip peripheral modules in stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
contents mc9s08rc/rd/re/rg 8 freescale semiconductor chapter 4 memory 4.1 mc9s08rc/rd/re/rg memory map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.1.1 reset and interrupt vector assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.2 register addresses and bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.3 ram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41 4.4 flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 4.4.1 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.4.2 program and erase times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.4.3 program and erase command execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.4.4 burst program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.4.5 access errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.4.6 flash block protection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.4.7 vector redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 4.5 security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48 4.6 flash registers and control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 4.6.1 flash clock divider register (fcdiv). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 4.6.2 flash options register (fopt and nvopt) . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.6.3 flash configuration register (fcnfg) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 4.6.4 flash protection register (fprot and nvprot) . . . . . . . . . . . . . . . . . . . . . . 52 4.6.5 flash status register (fstat) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 4.6.6 flash command register (fcmd) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 chapter 5 resets, interrupts, and system configuration 5.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 7 5.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 7 5.3 mcu reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 5.4 computer operating properly (cop) watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 5.5 interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 5.5.1 interrupt stack frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 5.5.2 external interrupt request (irq) pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 5.5.3 interrupt vectors, sources, and local masks . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 5.6 low-voltage detect (lvd) system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 5.6.1 power-on reset operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.6.2 lvd reset operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.6.3 lvd interrupt and safe state operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 5.6.4 low-voltage warning (lvw) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 9 mc9s08rc/rd/re/rg 5.7 real-time interrupt (rti) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 5.8 reset, interrupt, and system control registers and control bits . . . . . . . . . . . . . . 64 5.8.1 interrupt pin request status and control register (irqsc) . . . . . . . . . . . . . . . . 64 5.8.2 system reset status register (srs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 5.8.3 system background debug force reset register (sbdfr). . . . . . . . . . . . . . . . 67 5.8.4 system options register (sopt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 5.8.5 system device identification register (sdidh, sdidl) . . . . . . . . . . . . . . . . . . . 69 5.8.6 system real-time interrupt status and control register (srtisc) . . . . . . . . . . 69 5.8.7 system power management status and control 1 register (spmsc1) . . . . . . . 71 5.8.8 system power management status and control 2 register (spmsc2) . . . . . . . 72 chapter 6 central processor unit (cpu) 6.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3 6.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4 6.3 programmer? model and cpu registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 6.3.1 accumulator (a) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 6.3.2 index register (h:x). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 6.3.3 stack pointer (sp) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 6.3.4 program counter (pc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 6.3.5 condition code register (ccr). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 6.4 addressing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.1 inherent addressing mode (inh) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.2 relative addressing mode (rel). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.3 immediate addressing mode (imm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.4 direct addressing mode (dir) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 6.4.5 extended addressing mode (ext). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 6.4.6 indexed addressing mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 6.5 special operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 6.5.1 reset sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 6.5.2 interrupt sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 6.5.3 wait mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 6.5.4 stop mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 6.5.5 bgnd instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 6.6 hcs08 instruction set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
contents mc9s08rc/rd/re/rg 10 freescale semiconductor chapter 7 carrier modulator timer (cmt) module 7.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3 7.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4 7.3 cmt block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 7.4 pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 7.5 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 7.5.1 carrier generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 7.5.2 modulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 7.5.3 extended space operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 7.5.4 transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 7.5.5 cmt interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 7.5.6 wait mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 7.5.7 stop mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 7.5.8 background mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 7.6 cmt registers and control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 7.6.1 carrier generator data registers (cmtcgh1, cmtcgl1, cmtcgh2, and cmtcgl2) 104 7.6.2 cmt output control register (cmtoc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 7.6.3 cmt modulator status and control register (cmtmsc) . . . . . . . . . . . . . . . . . 107 7.6.4 cmt modulator data registers (cmtcmd1, cmtcmd2, cmtcmd3, and cmtcmd4) 109 chapter 8 parallel input/output 8.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 8.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 8.3 pin descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 8.3.1 port a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 8.3.2 port b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 8.3.3 port c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 8.3.4 port d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 8.3.5 port e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 8.4 parallel i/o controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 8.4.1 data direction control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 8.4.2 internal pullup control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 8.5 stop modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 8.6 parallel i/o registers and control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 11 mc9s08rc/rd/re/rg 8.6.1 port a registers (ptad, ptape, and ptadd) . . . . . . . . . . . . . . . . . . . . . . . . . 115 8.6.2 port b registers (ptbd, ptbpe, and ptbdd) . . . . . . . . . . . . . . . . . . . . . . . . . 117 8.6.3 port c registers (ptcd, ptcpe, and ptcdd) . . . . . . . . . . . . . . . . . . . . . . . . 118 8.6.4 port d registers (ptdd, ptdpe, and ptddd) . . . . . . . . . . . . . . . . . . . . . . . . 119 8.6.5 port e registers (pted, ptepe, and ptedd) . . . . . . . . . . . . . . . . . . . . . . . . . 120 chapter 9 keyboard interrupt (kbi) module 9.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 9.2 kbi block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 9.3 keyboard interrupt (kbi) module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 9.3.1 pin enables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 9.3.2 edge and level sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 9.3.3 kbi interrupt controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 9.4 kbi registers and control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 9.4.1 kbi x status and control register (kbixsc) . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 9.4.2 kbi x pin enable register (kbixpe) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 chapter 10 timer/pwm module (tpm) module 10.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 7 10.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 7 10.3 tpm block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 10.4 pin descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 10.4.1 external tpm clock sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 10.4.2 tpm1chn ?tpm1 channel n i/o pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 10.5 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 10.5.1 counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 10.5.2 channel mode selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 10.5.3 center-aligned pwm mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 10.6 tpm interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 10.6.1 clearing timer interrupt flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 10.6.2 timer overflow interrupt description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 10.6.3 channel event interrupt description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 10.6.4 pwm end-of-duty-cycle events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 10.7 tpm registers and control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 10.7.1 timer x status and control register (tpm1sc) . . . . . . . . . . . . . . . . . . . . . . . . 136 10.7.2 timer x counter registers (tpm1cnth:tpm1cntl) . . . . . . . . . . . . . . . . . . . 138
contents mc9s08rc/rd/re/rg 12 freescale semiconductor 10.7.3 timer x counter modulo registers (tpm1modh:tpm1modl) . . . . . . . . . . . . 139 10.7.4 timer x channel n status and control register (tpm1cnsc) . . . . . . . . . . . . . 140 10.7.5 timer x channel value registers (tpm1cnvh:tpm1cnvl) . . . . . . . . . . . . . . 142 chapter 11 serial communications interface (sci) module 11.1 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4 11.2 sci system description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 11.3 baud rate generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 11.4 transmitter functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 11.4.1 transmitter block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 11.4.2 send break and queued idle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 11.5 receiver functional description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 11.5.1 receiver block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 11.5.2 data sampling technique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 11.5.3 receiver wakeup operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 11.6 interrupts and status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 11.7 additional sci functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 11.7.1 8- and 9-bit data modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 11.8 stop mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 11.8.1 loop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 11.8.2 single-wire operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 11.9 sci registers and control bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 11.9.1 sci baud rate registers (sci1bdh, sci1bhl) . . . . . . . . . . . . . . . . . . . . . . . . 153 11.9.2 sci control register 1 (sci1c1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 11.9.3 sci control register 2 (sci1c2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 11.9.4 sci status register 1 (sci1s1). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 11.9.5 sci status register 2 (sci1s2). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 11.9.6 sci control register 3 (sci1c3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 11.9.7 sci data register (sci1d) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 chapter 12 serial peripheral interface (spi) module 12.1 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2 12.2 block diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 12.2.1 spi system block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 12.2.2 spi module block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 12.2.3 spi baud rate generation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 13 mc9s08rc/rd/re/rg 12.3 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 12.3.1 spi clock formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 12.3.2 spi pin controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 12.3.3 spi interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 12.3.4 mode fault detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 12.4 spi registers and control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 12.4.1 spi control register 1 (spi1c1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 12.4.2 spi control register 2 (spi1c2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 12.4.3 spi baud rate register (spi1br). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 12.4.4 spi status register (spi1s) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 12.4.5 spi data register (spi1d). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 chapter 13 analog comparator (acmp) module 13.1 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 8 13.2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 13.3 pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 13.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 13.4.1 interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 13.4.2 wait mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 13.4.3 stop mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 13.4.4 background mode operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 13.5 acmp status and control register (acmp1sc) . . . . . . . . . . . . . . . . . . . . . . . . . . 180 chapter 14 development support 14.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3 14.2 features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4 14.3 background debug controller (bdc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 14.3.1 bkgd pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 14.3.2 communication details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 14.3.3 bdc commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 14.3.4 bdc hardware breakpoint. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 14.4 on-chip debug system (dbg) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 14.4.1 comparators a and b. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 14.4.2 bus capture information and fifo operation . . . . . . . . . . . . . . . . . . . . . . . . . . 194 14.4.3 change-of-flow information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 14.4.4 tag vs. force breakpoints and triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
contents mc9s08rc/rd/re/rg 14 freescale semiconductor 14.4.5 trigger modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 14.4.6 hardware breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 14.5 registers and control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 14.5.1 bdc registers and control bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 14.5.2 system background debug force reset register (sbdfr). . . . . . . . . . . . . . . 199 14.5.3 dbg registers and control bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 appendix c electrical characteristics c.1 introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 c.2 absolute maximum ratings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 c.3 thermal characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 c.4 electrostatic discharge (esd) protection characteristics . . . . . . . . . . . . . . . . . . . 209 c.5 dc characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 c.6 supply current characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 c.7 analog comparator (acmp) electricals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 c.8 oscillator characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 c.9 ac characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 c.9.1 control timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 c.9.2 timer/pwm (tpm) module timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 c.9.3 spi timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 c.10 flash specifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 appendix d ordering information and mechanical drawings d.1 ordering information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 d.2 mechanical drawings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 d.2.1 28-pin soic package drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 d.2.2 28-pin pdip package drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 d.2.3 32-pin lqfp package drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 d.2.4 44-pin lqfp package drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 15 mc9s08rc/rd/re/rg chapter 1 introduction 1.1 overview the mc9s08rc/rd/re/rg are members of the low-cost, high-performance hcs08 family of 8-bit microcontroller units (mcus). all mcus in this family use the enhanced hcs08 core and are available with a variety of modules, memory sizes, memory types, and package types. 1.2 features features have been organized to reflect: standard features of the hcs08 family additional features of the mc9s08rc/rd/re/rg mcu 1.2.1 standard features of the hcs08 family hcs08 cpu (central processor unit) hc08 instruction set with added bgnd instruction background debugging system (see also the development support section) breakpoint capability to allow single breakpoint setting during in-circuit debugging (plus two more breakpoints in on-chip debug module) debug module containing two comparators and nine trigger modes. eight deep fifo for storing change-of-flow addresses and event-only data. debug module supports both tag and force breakpoints. support for up to 32 interrupt/reset sources power-saving modes: wait plus three stops system protection features: optional computer operating properly (cop) reset low-voltage detection with reset or interrupt illegal opcode detection with reset illegal address detection with reset (some devices don? have illegal addresses) 1.2.2 features of mc9s08rc/rd/re/rg series of mcus 8 mhz internal bus frequency on-chip in-circuit programmable flash memory with block protection and security option (see table 1-1 for device specific information) on-chip random-access memory (ram) (see table 1-1 for device specific information)
introduction mc9s08rc/rd/re/rg 16 freescale semiconductor low power oscillator capable of operating from crystal or resonator from 1 to 16 mhz on-chip analog comparator with internal reference (acmp1) see table 1-1 full rail-to-rail supply operation option to compare to a fixed internal bandgap reference voltage serial communications interface module (sci1) ?see table 1-1 serial peripheral interface module (spi1) ?see table 1-1 2-channel, 16-bit timer/pulse-width modulator (tpm1) module with selectable input capture, output compare, and edge-aligned or center-aligned pwm capability on each channel. keyboard interrupt ports (kbi1, kbi2) providing 12 keyboard interrupts eight with falling-edge/low-level plus four with selectable polarity carrier modulator timer (cmt) with dedicated infrared output (iro) pin drives iro pin for remote control communications can be disconnected from iro pin and used as output compare timer iro output pin has high-current sink capability eight high-current pins (limited by maximum package dissipation) software selectable pullups on ports when used as input. selection is on an individual port bit basis. during output mode, pullups are disengaged. 39 general-purpose input/output (i/o) pins, depending on package selection four packages available 28-pin plastic dual in-line package (pdip) 28-pin small outline integrated circuit (soic) 32-pin low-profile quad flat package (lqfp) 44-pin low-profile quad flat package (lqfp) 1.2.3 devices in the mc9s08rc/rd/re/rg series table 1-1 below lists the devices available in the mc9s08rc/rd/re/rg series and summarizes the differences in functions and configuration between them. table 1-1 devices in the mc9s08rc/rd/re/rg series device flash ram (1) notes : 1. 3s08rc/rd/re8/16 rom mcu devices have 512 bytes ram instead of 1k bytes. acmp (2) 2. only available in 32- or 44-pin lqfp packages. sci spi 9s08rg32/60 32k/60k 2k/2k yes yes yes 9s08re8/16/32/60 8/16k/32k/60k 1k/1k/2k/2k yes yes no 9s08rd8/16/32/60 8/16k/32k/60k 1k/1k/2k/2k no yes no 9s08rc8/16/32/60 8/16k/32k/60k 1k/1k/2k/2k yes no no
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 17 mc9s08rc/rd/re/rg 1.3 mcu block diagram this block diagram shows the structure of the mc9s08rc/rd/re/rg mcus. figure 1-1 mc9s08rc/rd/re/rg block diagram ptd3 ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 ptc1/kbi2p1 ptc0/kbi2p0 v ss v dd ptb3 ptb2 pta7/kbi1p7 ptb0/txd1 ptb1/rxd1 ptd2/irq ptd1/ reset ptd0/bkgd/ms ptc7/ ss1 ptc6/spsck1 ptc5/miso1 ptc4/mosi1 ptc3/kbi2p3 ptc2/kbi2p2 port a port c port d port b 8-bit keyboard interrupt module (kbi1) serial peripheral interface module (spi1) user flash user ram (rc/rd/re/rg32/60 = 2048 bytes) debug module (dbg) (rc/rd/re/rg60 = 63,364 bytes) hcs08 core bdc cpu notes: 1. port pins are software configurable with pullup device if input port 2. pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . 3. irq pin contains software configurable pullup/pulldown device if irq enabled (irqpe = 1) 4. the reset pin contains integrated pullup device enabled if reset enabled (rstpe = 1) 5. high current drive 6. pins pta[7:0] contain both pullup and pulldown devices. pulldown available when kbi enabled (kbi1pn = 1). notes notes 1, 5 2-channel timer/pwm module (tpm1) pte7 port e ptb5 ptb4 pte6 ptb7/tpm1ch1 module (acmp1) hcs08 system control resets and interrupts modes of operation power management voltage regulator rti analog comparator cop irq lvd internal bus low-power oscillator interface module (sci1) serial communications 7 pta1/kbi1p1 8 pte0 note 1 notes1, 2, 6 note 1 (rc/rd/re/rg32 = 32,768 bytes) (rc/rd/re8/16 = 1024 bytes) (rc/rd/re16 = 16,384 bytes) xtal extal carrier modulator timer module (cmt) 1, 3, 4 4-bit keyboard interrupt module (kbi2) iro note 5 pta0/kbi1p0 (rc/rd/re8 = 8192 bytes)
introduction mc9s08rc/rd/re/rg 18 freescale semiconductor table 1-2 lists the functional versions of the on-chip modules. 1.4 system clock distribution figure 1-2 system clock distribution diagram figure 1-2 shows a simplified clock connection diagram for the mcu. the cpu operates at the input frequency of the oscillator. the bus clock frequency is half of the oscillator frequency and is used by all of the internal circuits with the exception of the cpu and rti. the rti can use either the oscillator input or the internal rti oscillator as its clock source. table 1-2 block versions module version analog comparator (acmp) 1 carrier modulator transmitter (cmt) 1 keyboard interrupt (kbi) 1 serial communications interface (sci) 1 serial peripheral interface (spi) 3 timer pulse-width modulator (tpm) 1 central processing unit (cpu) 2 debug module (dbg) 1 flash 1 system control 2 tpm cmt sci spi bdc cpu acmp ram flash osc oscout* 2 system logic busclk flash has frequency requirements for program and erase operation. see appendix a. control rti rti osc rticlks * oscout is the alternate bdc clock source for the mc9s08rc/rd/re/rg.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 19 mc9s08rc/rd/re/rg chapter 2 pins and connections 2.1 introduction this section describes signals that connect to package pins. it includes a pinout diagram, a table of signal properties, and detailed discussion of signals. 2.2 device pin assignment figure 2-1 mc9s08rc/rd/re/rg in 44-pin lqfp package 44 34 43 42 41 40 39 38 37 36 35 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 21 22 33 32 31 30 29 28 27 26 25 24 12 23 ptb0/txd1 ptb5 ptb6 ptb7/tpm1ch1 ptb1/rxd1 ptb2 ptb3 ptb4 v dd v ss iro pte3 pte2 pte1 pte0 ptc3/kbi2p3 ptc2/kbi2p2 ptc1/kbi2p1 ptc0/kbi2p0 ptc4/mosi1 ptc5/miso1 ptc6/spsck1 xtal extal ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 ptd0/bkgd/ms ptd1/ reset ptc7/ ss1 ptd2/irq ptd3 pta3/kbi1p3 pte4 pte7 pta7/kbi1p7 pta6/kbi1p6 pta5/kbi1p5 pta4/kbi1p4 pta0/kbi1p0 pte5 pte6 pta2/kbi1p2 pta1/kbi1p1
pins and connections mc9s08rc/rd/re/rg 20 freescale semiconductor figure 2-2 mc9s08rc/rd/re/rg in 32-pin lqfp package ptb7/tpm1ch1 pta0/kbi1p0 ptb6 iro v ss v dd ptb2 ptb1/rxd1 ptb0/txd1 ptd6/tpm1ch0 ptd5/acmp1+ ptd4/acmp1 extal xtal ptd2/irq ptd1/ reset ptd0/bkgd/ms pta7/kbi1p7 pta6/kbi1p6 pta5/kbi1p5 pta4/kbi1p4 pta3/kbi1p3 pta2/kbi1p2 pta1/kbi1p1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 16 ptc7/ ss1 ptc0/kbi2p0 ptc1/kbi2p1 ptc2/kbi2p2 ptc3/kbi2p3 ptc4/miso1 ptc5/miso1 ptc6/spsck1
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 21 mc9s08rc/rd/re/rg figure 2-3 mc9s08rc/rd/re/rg in 28-pin soic package and 28-pin pdip package 2.3 recommended system connections figure 2-4 shows pin connections that are common to almost all mc9s08rc/rd/re/rg application systems. a more detailed discussion of system connections follows. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 ptb2 ptc3/kbi2p3 xtal extal ptd6/tpm1ch0 pta0/kbi1p0 pta1/kbi1p1 pta2/kbi1p2 pta3/kbi1p3 pta4/kbi1p4 ptc6/spsck1 ptc7/ ss1 ptc4/mosi1 ptc5/miso1 pta6/kbi1p6 pta5/kbi1p5 ptd0/bkgd/ms ptd1/ reset pta7/kbi1p7 ptb0/txd1 ptb1/rxd1 v dd v ss iro ptb7/tpm1ch1 ptc0/kbi2p0 ptc1/kbi2p1 ptc2/kbi2p2
pins and connections mc9s08rc/rd/re/rg 22 freescale semiconductor figure 2-4 basic system connections v dd v ss xtal extal bkgd/ms reset optional manual reset port a v dd 1 background header c1 c2 x1 r f c by 0.1 f c blk 10 f + 3 v + system power i/o and peripheral interface to system application pta0/kbi1p0 pta1/kbi1p1 pta2/kbi1p2 pta3/kbi1p3 pta4/kbi1p4 pta5/kbi1p5 pta6/kbi1p6 pta7/kbi1p7 v dd port b ptb0/txd1 ptb1/rxd1 ptb2 ptb3 ptb4 ptb5 ptb6 ptb7/tpm1ch1 port c ptc0/kbi2p0 ptc1/kbi2p1 ptc2/kbi2p2 ptc3/kbi2p3 ptc4/mosi1 ptc5/miso1 ptc6/spsck1 ptc7/ ss1 port d ptd0/bkgd/ms ptd1/ reset ptd2/irq ptd3 ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 port e pte0 pte1 pte2 pte3 pte4 pte5 pte6 pte7 notes: 1. bkgd/ms is the same pin as ptd0. 2. reset is the same pin as ptd1. note 1 mc9s08rc/rd/re/rg note 2 iro
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 23 mc9s08rc/rd/re/rg 2.3.1 power v dd and v ss are the primary power supply pins for the mcu. this voltage source supplies power to all i/o buffer circuitry and to an internal voltage regulator. the internal voltage regulator provides a regulated lower-voltage source to the cpu and other internal circuitry of the mcu. typically, application systems have two separate capacitors across the power pins. in this case, there should be a bulk electrolytic capacitor, such as a 10- f tantalum capacitor, to provide bulk charge storage for the overall system and a 0.1- f ceramic bypass capacitor located as near to the mcu power pins as practical to suppress high-frequency noise. 2.3.2 oscillator the oscillator in the mc9s08rc/rd/re/rg is a traditional pierce oscillator that can accommodate a crystal or ceramic resonator in the range of 1 mhz to 16 mhz. refer to figure 2-4 for the following discussion. r f should be a low-inductance resistor such as a carbon composition resistor. wire-wound resistors, and some metal film resistors, have too much inductance. c1 and c2 normally should be high-quality ceramic capacitors specifically designed for high-frequency applications. r f is used to provide a bias path to keep the extal input in its linear range during crystal startup and its value is not generally critical. typical systems use 1 m ? . higher values are sensitive to humidity and lower values reduce gain and (in extreme cases) could prevent startup. c1 and c2 are typically in the 5-pf to 25-pf range and are chosen to match the requirements of a specific crystal or resonator. be sure to take into account printed circuit board (pcb) capacitance and mcu pin capacitance when sizing c1 and c2. the crystal manufacturer typically specifies a load capacitance that is the series combination of c1 and c2, which are usually the same size. as a first-order approximation, use 5 pf as an estimate of combined pin and pcb capacitance for each oscillator pin (extal and xtal). 2.3.3 ptd1/ reset the external pin reset function is shared with an output-only port function on the ptd1/ reset pin. the reset function is enabled when rstpe in sopt is set. rstpe is set following any reset of the mcu and must be cleared in order to use this pin as an output-only port. whenever any reset is initiated (whether from an external signal or from an internal system), the reset pin is driven low for about 34 cycles of f self_reset , released, and sampled again about 38 cycles of f self_reset later. if reset was caused by an internal source such as low-voltage reset or watchdog timeout, the circuitry expects the reset pin sample to return a logic 1. if the pin is still low at this sample point, the reset is assumed to be from an external source. the reset circuitry decodes the cause of reset and records it by setting a corresponding bit in the system control reset status register (srs). never connect any significant capacitance to the reset pin because that would interfere with the circuit and sequence that detects the source of reset. if an external capacitance prevents the reset pin from rising to a valid logic 1 before the reset sample point, all resets will appear to be external resets.
pins and connections mc9s08rc/rd/re/rg 24 freescale semiconductor 2.3.4 background/mode select (ptd0/bkgd/ms) the background/mode select function is shared with an output-only port function on the ptd0/bkdg/ms pin. while in reset, the pin functions as a mode select pin. immediately after reset rises, the pin functions as the background pin and can be used for background debug communication. while functioning as a background/mode select pin, this pin has an internal pullup device enabled. to use as an output-only port, bkgdpe in sopt must be cleared. if nothing is connected to this pin, the mcu will enter normal operating mode at the rising edge of reset. if a debug system is connected to the 6-pin standard background debug header, it can hold bkgd/ms low during the rising edge of reset, which forces the mcu to active background mode. the bkgd pin is used primarily for background debug controller (bdc) communications using a custom protocol that uses 16 clock cycles of the target mcu? bdc clock per bit time. the target mcu? bdc clock could be as fast as the bus clock rate, so there should never be any significant capacitance connected to the bkgd/ms pin that could interfere with background serial communications. although the bkgd pin is a pseudo open-drain pin, the background debug communication protocol provides brief, actively driven, high speedup pulses to ensure fast rise times. small capacitances from cables and the absolute value of the internal pullup device play almost no role in determining rise and fall times on the bkgd pin. 2.3.5 iro pin description the iro pin is the output of the cmt. see carrier modulator timer (cmt) module for a detailed description of this pin function. 2.3.6 general-purpose i/o and peripheral ports the remaining pins are shared among general-purpose i/o and on-chip peripheral functions such as timers and serial i/o systems. (not all pins are available in all packages. see table 2-2 .) immediately after reset, all 37 of these pins are configured as high-impedance general-purpose inputs with internal pullup devices disabled. note: to avoid extra current drain from floating input pins, the reset initialization routine in the application program should either enable on-chip pullup devices or change the direction of unused pins to outputs so the pins do not float. for information about controlling these pins as general-purpose i/o pins, see the parallel input/output section. for information about how and when on-chip peripheral systems use these pins, refer to the appropriate section from table 2-1 .
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 25 mc9s08rc/rd/re/rg when an on-chip peripheral system is controlling a pin, data direction control bits still determine what is read from port data registers even though the peripheral module controls the pin direction by controlling the enable for the pin? output buffer. see the parallel input/output section for more details. pullup enable bits for each input pin control whether on-chip pullup devices are enabled whenever the pin is acting as an input even if it is being controlled by an on-chip peripheral module. when the pta7?ta4 pins are controlled by the kbi module and are configured for rising-edge/high-level sensitivity, the pullup enable control bits enable pulldown devices rather than pullup devices. similarly, when ptd2 is configured as the irq input and is set to detect rising edges, the pullup enable control bit enables a pulldown device rather than a pullup device. table 2-1 pin sharing references port pins alternate function reference (1) notes : 1. see this section for information about modules that share these pins. pta7?ta0 kbi1p7?bi1p0 keyboard interrupt (kbi) module ptb7 tpm1ch1 timer/pwm module (tpm) module ptb6?tb2 parallel input/output ptb1 ptb0 rxd1 txd1 serial communications interface (sci) module ptc7 ptc6 ptc5 ptc4 ss1 spsck1 miso1 mosi1 serial peripheral interface (spi) module ptc3?tc0 kbi2p3?bi2p0 keyboard interrupt (kbi) module ptd6 tpm1ch0 timer/pwm module (tpm) module ptd5 ptd4 acmp1+ acmp1 analog comparator (acmp) module ptd2 irq resets, interrupts, and system con?uration ptd1 reset ptd0 bkgd/ms pte7?te0 parallel input/output
pins and connections mc9s08rc/rd/re/rg 26 freescale semiconductor 2.3.7 signal properties summary table 2-2 summarizes i/o pin characteristics. these characteristics are determined by the way the common pin interfaces are hardwired to internal circuits. table 2-2 signal properties pin name dir (1) high current pin pullup (2) comments v dd v ss xtal o crystal oscillator output extal i crystal oscillator input iro o y infrared output pta0/kbi1p0 i n swc pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . pta1/kbi1p1 i/o n swc pta2/kbi1p2 i/o n swc pta3/kbi1p3 i/o n swc pta4/kbi1p4 i/o n swc pta5/kbi1p5 i/o n swc pta6/kbi1p6 i/o n swc pta7/kbi1p7 i/o n swc ptb0/txd1 i/o y swc ptb1/rxd1 i/o y swc ptb2 i/o y swc ptb3 i/o y swc available only in 44-lqfp package ptb4 i/o y swc available only in 44-lqfp package ptb5 i/o y swc available only in 44-lqfp package ptb6 i/o y swc available only in 32- or 44-lqfp packages ptb7/tpm1ch1 i/o y swc ptc0/kbi2p0 i/o n swc ptc1/kbi2p1 i/o n swc ptc2/kbi2p2 i/o n swc ptc3/kbi2p3 i/o n swc ptc4/mosi1 i/o n swc ptc5/miso1 i/o n swc ptc6/spsck1 i/o n swc ptc7/ ss1 i/o n swc ptd0/bkgd/ms i/o n swc (3) output-only when con?ured as ptd0 pin. pullup enabled. ptd1/ reset i/o n swc (3) output-only when con?ured as ptd1 pin. ptd2/irq i/o n swc (4) available only in 32- or 44-lqfp packages ptd3 i/o n swc available only in 44-lqfp package ptd4/acmp1 i/o n swc available only in 32- or 44-lqfp packages ptd5/acmp1+ i/o n swc available only in 32- or 44-lqfp packages
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 27 mc9s08rc/rd/re/rg ptd6/tpm1ch0 i/o n swc pte0 i/o n swc available only in 44-lqfp package pte1 i/o n swc available only in 44-lqfp package pte2 i/o n swc available only in 44-lqfp package pte3 i/o n swc available only in 44-lqfp package pte4 i/o n swc available only in 44-lqfp package pte5 i/o n swc available only in 44-lqfp package pte6 i/o n swc available only in 44-lqfp package pte7 i/o n swc available only in 44-lqfp package notes : 1. unless otherwise indicated, all digital inputs have input hysteresis. 2. swc is software-controlled pullup resistor, the register is associated with the respective port. 3. when these pins are configured as reset or bkgd/ms pullup device is enabled. 4. when configured for the irq function, this pin will have a pullup device enabled when the irq is set for falling edge detection and a pulldown device enabled when the irq is set for rising edge detection. table 2-2 signal properties (continued) pin name dir (1) high current pin pullup (2) comments
pins and connections mc9s08rc/rd/re/rg 28 freescale semiconductor
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 29 mc9s08rc/rd/re/rg chapter 3 modes of operation 3.1 introduction the operating modes of the mc9s08rc/rd/re/rg are described in this section. entry into each mode, exit from each mode, and functionality while in each of the modes are described. 3.2 features active background mode for code development wait mode: cpu shuts down to conserve power system clocks running full voltage regulation maintained stop modes: system clocks stopped; voltage regulator in standby stop1 ?full power down of internal circuits for maximum power savings stop2 ?partial power down of internal circuits, ram remains operational stop3 ?all internal circuits powered for fast recovery 3.3 run mode this is the normal operating mode for the mc9s08rc/rd/re/rg. this mode is selected when the bkgd/ms pin is high at the rising edge of reset. in this mode, the cpu executes code from internal memory with execution beginning at the address fetched from memory at $fffe:$ffff after reset. 3.4 active background mode the active background mode functions are managed through the background debug controller (bdc) in the hcs08 core. the bdc, together with the on-chip debug module (dbg), provide the means for analyzing mcu operation during software development. active background mode is entered in any of five ways: when the bkgd/ms pin is low at the rising edge of reset when a background command is received through the bkgd pin when a bgnd instruction is executed when encountering a bdc breakpoint when encountering a dbg breakpoint
modes of operation mc9s08rc/rd/re/rg 30 freescale semiconductor after active background mode is entered, the cpu is held in a suspended state waiting for serial background commands rather than executing instructions from the user? application program. background commands are of two types: non-intrusive commands, defined as commands that can be issued while the user program is running. non-intrusive commands can be issued through the bkgd pin while the mcu is in run mode; non-intrusive commands can also be executed when the mcu is in the active background mode. non-intrusive commands include: memory access commands memory-access-with-status commands bdc register access commands background command active background commands, which can only be executed while the mcu is in active background mode, include commands to: read or write cpu registers trace one user program instruction at a time leave active background mode to return to the user? application program (go) the active background mode is used to program a bootloader or user application program into the flash program memory before the mcu is operated in run mode for the first time. when the mc9s08rc/rd/re/rg is shipped from the freescale semiconductor factory, the flash program memory is usually erased so there is no program that could be executed in run mode until the flash memory is initially programmed. the active background mode can also be used to erase and reprogram the flash memory after it has been previously programmed. for additional information about the active background mode, refer to the development support section. 3.5 wait mode wait mode is entered by executing a wait instruction. upon execution of the wait instruction, the cpu enters a low-power state in which it is not clocked. the i bit in ccr is cleared when the cpu enters the wait mode, enabling interrupts. when an interrupt request occurs, the cpu exits the wait mode and resumes processing, beginning with the stacking operations leading to the interrupt service routine. only the background command and memory-access-with-status commands are available when the mcu is in wait mode. the memory-access-with-status commands do not allow memory access, but they report an error indicating that the mcu is in either stop or wait mode. the background command can be used to wake the mcu from wait mode and enter active background mode.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 31 mc9s08rc/rd/re/rg 3.6 stop modes one of three stop modes is entered upon execution of a stop instruction when the stope bit in the system option register is set. in all stop modes, all internal clocks are halted. if the stope bit is not set when the cpu executes a stop instruction, the mcu will not enter any of the stop modes and an illegal opcode reset is forced. the stop modes are selected by setting the appropriate bits in spmsc2. table 3-1 summarizes the behavior of the mcu in each of the stop modes. 3.6.1 stop1 mode stop1 mode provides the lowest possible standby power consumption by causing the internal circuitry of the mcu to be powered down. to enter stop1, the user must execute a stop instruction with the pdc bit in spmsc2 set and the ppdc bit clear. stop1 can be entered only if the lvd reset is disabled (lvdre = 0). when the mcu is in stop1 mode, all internal circuits that are powered from the voltage regulator are turned off. the voltage regulator is in a low-power standby state, as are the osc and acmp. exit from stop1 is done by asserting any of the wakeup pins on the mcu: reset, irq, or kbi, which have been enabled. irq and kbi pins are always active-low when used as wakeup pins in stop1 regardless of how they were configured before entering stop1. upon wakeup from stop1 mode, the mcu will start up as from a power-on reset (por). the cpu will take the reset vector. 3.6.2 stop2 mode stop2 mode provides very low standby power consumption and maintains the contents of ram and the current state of all of the i/o pins. to select entry into stop2 upon execution of a stop instruction, the user must execute a stop instruction with the ppdc and pdc bits in spmsc2 set. stop2 can be entered only if lvdre = 0. before entering stop2 mode, the user must save the contents of the i/o port registers, as well as any other memory-mapped registers that they want to restore after exit of stop2, to locations in ram. upon exit from stop2, these values can be restored by user software. table 3-1 stop mode behavior mode pdc ppdc cpu, digital peripherals, flash ram osc acmp regulator i/o pins rti stop1 1 0 off off off standby standby reset off stop2 1 1 off standby off standby standby states held optionally on stop3 0 don? care standby standby off standby standby states held optionally on
modes of operation mc9s08rc/rd/re/rg 32 freescale semiconductor when the mcu is in stop2 mode, all internal circuits that are powered from the voltage regulator are turned off, except for the ram. the voltage regulator is in a low-power standby state, as is the acmp. upon entry into stop2, the states of the i/o pins are latched. the states are held while in stop2 mode and after exiting stop2 mode until a 1 is written to ppdack in spmsc2. exit from stop2 is done by asserting any of the wakeup pins: reset, irq, or kbi that have been enabled, or through the real-time interrupt. irq and kbi pins are always active-low when used as wakeup pins in stop2 regardless of how they were configured before entering stop2. upon wakeup from stop2 mode, the mcu will start up as from a power-on reset (por) except pin states remain latched. the cpu will take the reset vector. the system and all peripherals will be in their default reset states and must be initialized. after waking up from stop2, the ppdf bit in spmsc2 is set. this flag may be used to direct user code to go to a stop2 recovery routine. ppdf remains set and the i/o pin states remain latched until a 1 is written to ppdack in spmsc2. for pins that were configured as general-purpose i/o, the user must copy the contents of the i/o port registers, which have been saved in ram, back to the port registers before writing to the ppdack bit. if the port registers are not restored from ram before writing to ppdack, then the register bits will be in their reset states when the i/o pin latches are opened and the i/o pins will switch to their reset states. for pins that were configured as peripheral i/o, the user must reconfigure the peripheral module that interfaces to the pin before writing to the ppdack bit. if the peripheral module is not enabled before writing to ppdack, the pins will be controlled by their associated port control registers when the i/o latches are opened. 3.6.3 stop3 mode upon entering stop3 mode, all of the clocks in the mcu, including the oscillator itself, are halted. the osc is turned off, the acmp is disabled, and the voltage regulator is put in standby. the states of all of the internal registers and logic, as well as the ram content, are maintained. the i/o pin states are not latched at the pin as in stop2. instead they are maintained by virtue of the states of the internal logic driving the pins being maintained. exit from stop3 is done by asserting reset, any asynchronous interrupt pin that has been enabled, or through the real-time interrupt. the asynchronous interrupt pins are the irq or kbi pins. if stop3 is exited by means of the reset pin, then the mcu will be reset and operation will resume after taking the reset vector. exit by means of an asynchronous interrupt or the real-time interrupt will result in the mcu taking the appropriate interrupt vector. a separate self-clocked source ( 1 khz) for the real-time interrupt allows a wakeup from stop2 or stop3 mode with no external components. when rtis2:rtis1:rtis0 = 0:0:0, the real-time interrupt function and this 1-khz source are disabled. power consumption is lower when the 1-khz source is disabled, but in that case the real-time interrupt cannot wake the mcu from stop.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 33 mc9s08rc/rd/re/rg 3.6.4 active bdm enabled in stop mode entry into the active background mode from run mode is enabled if the enbdm bit in bdcscr is set. this register is described in the development support section of this data sheet. if enbdm is set when the cpu executes a stop instruction, the system clocks to the background debug logic remain active when the mcu enters stop mode so background debug communication is still possible. in addition, the voltage regulator does not enter its low-power standby state but maintains full internal regulation. the mcu cannot enter either stop1 mode or stop2 mode if enbdm is set. most background commands are not available in stop mode. the memory-access-with-status commands do not allow memory access, but they report an error indicating that the mcu is in either stop or wait mode. the background command can be used to wake the mcu from stop and enter active background mode if the enbdm bit is set. after active background mode is entered, all background commands are available. table 3-2 summarizes the behavior of the mcu in stop when entry into the active background mode is enabled. 3.6.5 lvd reset enabled in stop mode the lvd system is capable of generating either an interrupt or a reset when the supply voltage drops below the lvd voltage. if the lvd reset is enabled in stop by setting the lvdre bit in spmsc1 when the cpu executes a stop instruction, then the voltage regulator remains active during stop mode. if the user attempts to enter either stop1 or stop2 with the lvd reset enabled (lvdre = 1) the mcu will instead enter stop3. table 3-3 summarizes the behavior of the mcu in stop when lvd reset is enabled. 3.6.6 on-chip peripheral modules in stop mode when the mcu enters any stop mode, system clocks to the internal peripheral modules are stopped. even in the exception case (enbdm = 1), where clocks are kept alive to the background debug logic, clocks to the peripheral systems are halted to reduce power consumption. table 3-2 bdm enabled stop mode behavior mode pdc ppdc cpu, digital peripherals, flash ram osc acmp regulator i/o pins rti stop3 don? care don? care standby standby on standby on states held optionally on table 3-3 lvd enabled stop mode behavior mode pdc ppdc cpu, digital peripherals, flash ram osc acmp regulator i/o pins rti stop3 don? care don? care standby standby on standby on states held optionally on
modes of operation mc9s08rc/rd/re/rg 34 freescale semiconductor i/o pins all i/o pin states remain unchanged when the mcu enters stop3 mode. if the mcu is configured to go into stop2 mode, all i/o pin states are latched before entering stop. pin states remain latched until the ppdack bit is written. if the mcu is configured to go into stop1 mode, all i/o pins are forced to their default reset state upon entry into stop. memory all ram and register contents are preserved while the mcu is in stop3 mode. all registers will be reset upon wakeup from stop2, but the contents of ram are preserved. the user may save any memory-mapped register data into ram before entering stop2 and restore the data upon exit from stop2. all registers will be reset upon wakeup from stop1 and the contents of ram are not preserved. the mcu must be initialized as upon reset. the contents of the flash memory are non-volatile and are preserved in any of the stop modes. osc ?in any of the stop modes, the osc stops running. tpm ?when the mcu enters stop mode, the clock to the tpm module stops. the modules halt operation. if the mcu is configured to go into stop2 or stop1 mode, the tpm module will be reset upon wakeup from stop and must be reinitialized. acmp ?when the mcu enters any stop mode, the acmp will enter a low-power standby state . no compare operation will occur while in stop. if the mcu is configured to go into stop2 or stop1 mode, the acmp will be reset upon wakeup from stop and must be reinitialized. kbi during stop3, the kbi pins that are enabled continue to function as interrupt sources. during stop1 or stop2, enabled kbi pins function as wakeup inputs. when functioning as a wakeup, a kbi pin is always active low regardless of how it was configured before entering stop1 or stop2. sci when the mcu enters stop mode, the clock to the sci module stops. the module halts operation. if the mcu is configured to go into stop2 or stop1 mode, the sci module will be reset upon wakeup from stop and must be reinitialized. spi when the mcu enters stop mode, the clock to the spi module stops. the module halts operation. if the mcu is configured to go into stop2 or stop1 mode, the spi module will be reset upon wakeup from stop and must be reinitialized. cmt ?when the mcu enters stop mode, the clock to the cmt module stops. the module halts operation. if the mcu is configured to go into stop2 or stop1 mode, the cmt module will be reset upon wakeup from stop and must be reinitialized. voltage regulator the voltage regulator enters a low-power standby state when the mcu enters any of the stop modes unless the lvd reset function is enabled or bdm is enabled.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 35 mc9s08rc/rd/re/rg chapter 4 memory 4.1 mc9s08rc/rd/re/rg memory map as shown in figure 4-1 , on-chip memory in the mc9s08rc/rd/re/rg series of mcus consists of ram, flash program memory for nonvolatile data storage, and i/o and control/status registers. the registers are divided into three groups: direct-page registers ($0000 through $0045 for 32k and 60k parts, and $0000 through $003f for 16k and 8k parts) high-page registers ($1800 through $182b) nonvolatile registers ($ffb0 through $ffbf) figure 4-1 mc9s08rc/rd/re/rg memory map direct page registers ram flash high page registers flash 2048 bytes 4026 bytes 59348 bytes $0000 $0045 $0046 $0845 $1800 $17ff $182b $182c $ffff $0846 $0000 $003f $0040 $043f $1800 $17ff $182b $182c $ffff $0440 $c000 $bfff mc9s08rc/rd/re/rg60 mc9s08rc/rd/re16 $0000 $0045 $0046 $0845 $1800 $17ff $182b $0846 $8000 mc9s08rc/rd/re/rg32 $182c direct page registers ram unimplemented high page registers flash 2048 bytes 4026 bytes 32768 bytes direct page registers ram unimplemented high page registers flash 1024 bytes (1) 5056 bytes 16384 bytes unimplemented 26580 bytes unimplemented 42964 bytes 1. mc3s08rc/rd/re16/8 rom mcu devices have 512 bytes of ram instead of 1k bytes. note: $0000 $003f $0040 $043f $1800 $17ff $182b $182c $ffff $0440 $e000 $dfff mc9s08rc/rd/re8 direct page registers ram unimplemented high page registers flash 1024 bytes (1) 5056 bytes 8192 bytes unimplemented 51156 bytes
memory mc9s08rc/rd/re/rg 36 freescale semiconductor 4.1.1 reset and interrupt vector assignments table 4-1 shows address assignments for reset and interrupt vectors. the vector names shown in this table are the labels used in the freescale-provided equate file for the mc9s08rc/rd/re/rg. for more details about resets, interrupts, interrupt priority, and local interrupt mask controls, refer to the resets, interrupts, and system configuration section. table 4-1 reset and interrupt vectors vector numbe r address (high/low) vector vector name 16 through 31 $ffc0:ffc1 $ffde:ffdf unused vector space (available for user program) 15 $ffe0:ffe1 spi (1) notes : 1. the spi module is not included on the mc9s08rc/rd/re devices. this vector location is unused for those devices. vspi1 14 $ffe2:ffe3 rti vrti 13 $ffe4:ffe5 kbi2 vkeyboard2 12 $ffe6:ffe7 kbi1 vkeyboard1 11 $ffe8:ffe9 acmp (2) 2. the analog comparator (acmp) module is not included on the mc9s08rd devices. this vector location is unused for those devices. vacmp1 10 $ffea:ffeb cmt vcmt 9 $ffec:ffed sci transmit (3) 3. the sci module is not included on the mc9s08rc devices. this vector location is unused for those devices. vsci1tx 8 $ffee:ffef sci receive (3) vsci1rx 7 $fff0:fff1 sci error (3) vsci1err 6 $fff2:fff3 tpm over?w vtpm1ovf 5 $fff4:fff5 tpm channel 1 vtpm1ch1 4 $fff6:fff7 tpm channel 0 vtpm1ch0 3 $fff8:fff9 irq virq 2 $fffa:fffb low voltage detect vlvd 1 $fffc:fffd swi vswi 0 $fffe:ffff reset vreset
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 37 mc9s08rc/rd/re/rg 4.2 register addresses and bit assignments the registers in the mc9s08rc/rd/re/rg are divided into these three groups: direct-page registers are located within the first 256 locations in the memory map, so they are accessible with efficient direct addressing mode instructions. high-page registers are used much less often, so they are located above $1800 in the memory map. this leaves more room in the direct page for more frequently used registers and variables. the nonvolatile register area consists of a block of 16 locations in flash memory at $ffb0?ffbf. nonvolatile register locations include: three values that are loaded into working registers at reset an 8-byte backdoor comparison key that optionally allows a user to gain controlled access to secure memory because the nonvolatile register locations are flash memory, they must be erased and programmed like other flash memory locations. direct-page registers can be accessed with efficient direct addressing mode instructions. bit manipulation instructions can be used to access any bit in any direct-page register. table 4-2 is a summary of all user-accessible direct-page registers and control bits. the direct page registers in table 4-2 can use the more efficient direct addressing mode, which requires only the lower byte of the address. because of this, the lower byte of the address in column one is shown in bold text. in table 4-3 and table 4-4 , the whole address in column one is shown in bold. in table 4-2 , table 4-3 , and table 4-4 , the register names in column two are shown in bold to set them apart from the bit names to the right. cells that are not associated with named bits are shaded. a shaded cell with a 0 indicates this unused bit always reads as a 0. shaded cells with dashes indicate unused or reserved bit locations that could read as 1s or 0s.
memory mc9s08rc/rd/re/rg 38 freescale semiconductor table 4-2 direct-page register summary address register name bit 7 654321 bit 0 $00 00 ptad ptad7 ptad6 ptad5 ptad4 ptad3 ptad2 ptad1 ptad0 $00 01 ptape ptape7 ptape6 ptape5 ptape4 ptape3 ptape2 ptape1 ptape0 $00 02 reserved $00 03 ptadd ptadd7 ptadd6 ptadd5 ptadd4 ptadd3 ptadd2 ptadd1 ptadd0 $00 04 ptbd ptbd7 ptbd6 ptbd5 ptbd4 ptbd3 ptbd2 ptbd1 ptbd0 $00 05 ptbpe ptbpe7 ptbpe6 ptbpe5 ptbpe4 ptbpe3 ptbpe2 ptbpe1 ptbpe0 $00 06 reserved $00 07 ptbdd ptbdd7 ptbdd6 ptbdd5 ptbdd4 ptbdd3 ptbdd2 ptbdd1 ptbdd0 $00 08 ptcd ptcd7 ptcd6 ptcd5 ptcd4 ptcd3 ptcd2 ptcd1 ptcd0 $00 09 ptcpe ptcpe7 ptcpe6 ptcpe5 ptcpe4 ptcpe3 ptcpe2 ptcpe1 ptcpe0 $00 0a reserved $00 0b ptcdd ptcdd7 ptcdd6 ptcdd5 ptcdd4 ptcdd3 ptcdd2 ptcdd1 ptcdd0 $00 0c ptdd 0 ptdd6 ptdd5 ptdd4 ptdd3 ptdd2 ptdd1 ptdd0 $00 0d ptdpe 0 ptdpe6 ptdpe5 ptdpe4 ptdpe3 ptdpe2 ptdpe1 ptdpe0 $00 0e reserved $00 0f ptddd 0 ptddd6 ptddd5 ptddd4 ptddd3 ptddd2 ptddd1 ptddd0 $00 10 pted pted7 pted6 pted5 pted4 pted3 pted2 pted1 pted0 $00 11 ptepe ptepe7 ptepe6 ptepe5 ptepe4 ptepe3 ptepe2 ptepe1 ptepe0 $00 12 reserved $00 13 ptedd ptedd7 ptedd6 ptedd5 ptedd4 ptedd3 ptedd2 ptedd1 ptedd0 $00 14 kbi1sc kbedg7 kbedg6 kbedg5 kbedg4 kbf kback kbie kbimod $00 15 kbi1pe kbipe7 kbipe6 kbipe5 kbipe4 kbipe3 kbipe2 kbipe1 kbipe0 $00 16 kbi2sc 0 0 0 0 kbf kback kbie kbimod $00 17 kbi2pe 0 0 0 0 kbipe3 kbipe2 kbipe1 kbipe0 $00 18 sci1bdh (1) 0 0 0 sbr12 sbr11 sbr10 sbr9 sbr8 $00 19 sci1bdl (1) sbr7 sbr6 sbr5 sbr4 sbr3 sbr2 sbr1 sbr0 $00 1a sci1c1 (1) loops sciswai rsrc m wake ilt pe pt $00 1b sci1c2 (1) tie tcie rie ilie te re rwu sbk $00 1c sci1s1 (1) tdre tc rdrf idle or nf fe pf $00 1d sci1s2 (1) 0 0 0 0 0 0 0 raf $00 1e sci1c3 (1) r8 t8 txdir 0 orie neie feie peie $00 1f sci1d (1) r7/t7 r6/t6 r5/t5 r4/t4 r3/t3 r2/t2 r1/t1 r0/t0 $00 20 cmtcgh1 ph7 ph6 ph5 ph4 ph3 ph2 ph1 ph0 $00 21 cmtcgl1 pl7 pl6 pl5 pl4 pl3 pl2 pl1 pl0 $00 22 cmtcgh2 sh7 sh6 sh5 sh4 sh3 sh2 sh1 sh0 $00 23 cmtcgl2 sl7 sl6 sl5 sl4 sl3 sl2 sl1 sl0 $00 24 cmtoc irol cmtpol iropen 00000 $00 25 cmtmsc eocf cmtdiv1 cmtdiv0 exspc base fsk eocie mcgen $00 26 cmtcmd1 mb15 mb14 mb13 mb12 mb11 mb10 mb9 mb8 $00 27 cmtcmd2 mb7 mb6 mb5 mb4 mb3 mb2 mb1 mb0
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 39 mc9s08rc/rd/re/rg $00 28 cmtcmd3 sb15 sb14 sb13 sb12 sb11 sb10 sb9 sb8 $00 29 cmtcmd4 sb7 sb6 sb5 sb4 sb3 sb2 sb1 sb0 $00 2a irqsc 0 0 irqedg irqpe irqf irqack irqie irqmod $00 2b acmp1sc (2) acme acbgs acf acie aco acmod1 acmod0 $00 2c $00 2f reserved $00 30 tpm1sc tof toie cpwms clksb clksa ps2 ps1 ps0 $00 31 tpm1cnth bit 15 14 13 12 11 10 9 bit 8 $00 32 tpm1cntl bit 7 654321 bit 0 $00 33 tpm1modh bit 15 14 13 12 11 10 9 bit 8 $00 34 tpm1modl bit 7 654321 bit 0 $00 35 tpm1c0sc ch0f ch0ie ms0b ms0a els0b els0a 0 0 $00 36 tpm1c0vh bit 15 14 13 12 11 10 9 bit 8 $00 37 tpm1c0vl bit 7 654321 bit 0 $00 38 tpm1c1sc ch1f ch1ie ms1b ms1a els1b els1a 0 0 $00 39 tpm1c1vh bit 15 14 13 12 11 10 9 bit 8 $00 3a tpm1c1vl bit 7 654321 bit 0 $00 3b $00 3f reserved $00 40 spi1c1 (3) spie spe sptie mstr cpol cpha ssoe lsbfe $00 41 spi1c2 (3) 0 0 0 modfen bidiroe 0 spiswai spc0 $00 42 spi1br (3) 0 sppr2 sppr1 sppr0 0 spr2 spr1 spr0 $00 43 spi1s (3) sprf 0 sptef modf 0 0 0 0 $00 44 reserved $00 45 spi1d (3) bit 7 654321 bit 0 notes : 1. the sci module is not included on the mc9s08rc devices. this is a reserved location for those devices. 2. the analog comparator (acmp) module is not included on the mc9s08rd devices. this is a reserved location for those devices. 3. the spi module is not included on the mc9s08rc/rd/re devices. these are reserved locations on the 32k and 60k versions of these devices. the address range $0040?004f are ram locations on the 16k and 8k devices. there are no mc9s08rg8/16 devices. table 4-2 direct-page register summary (continued) address register name bit 7 654321 bit 0
memory mc9s08rc/rd/re/rg 40 freescale semiconductor high-page registers, shown in table 4-3 , are accessed much less often than other i/o and control registers so they have been located outside the direct addressable memory space, starting at $1800. table 4-3 high-page register summary address register name bit 7 654321 bit 0 $1800 srs por pin cop ilop ilad (1) notes : 1. the ilad bit is only present on 16k and 8k versions of the devices. 0 lvd 0 $1801 sbdfr 0 0 0 0 0 0 0 bdfr $1802 sopt cope copt stope 0 0 bkgdpe rstpe $1803 $1804 reserved $1805 reserved 0 0 0 0 0 0 0 0 $1806 sdidh rev3 rev2 rev1 rev0 id11 id10 id9 id8 $1807 sdidl id7 id6 id5 id4 id3 id2 id1 id0 $1808 srtisc rtif rtiack rticlks rtie 0 rtis2 rtis1 rtis0 $1809 spmsc1 lvdf lvdack lvdie safe lvdre $180a spmsc2 lvwf lvwack 0 0 ppdf ppdack pdc ppdc $180b $180f reserved $1810 dbgcah bit 15 14 13 12 11 10 9 bit 8 $1811 dbgcal bit 7 654321 bit 0 $1812 dbgcbh bit 15 14 13 12 11 10 9 bit 8 $1813 dbgcbl bit 7 654321 bit 0 $1814 dbgfh bit 15 14 13 12 11 10 9 bit 8 $1815 dbgfl bit 7 654321 bit 0 $1816 dbgc dbgen arm tag brken rwa rwaen rwb rwben $1817 dbgt trgsel begin 0 0 trg3 trg2 trg1 trg0 $1818 dbgs af bf armf 0 cnt3 cnt2 cnt1 cnt0 $1819 $181f reserved $1820 fcdiv divld prdiv8 div5 div4 div3 div2 div1 div0 $1821 fopt keyen fnored 0 0 0 0 sec01 sec00 $1822 reserved $1823 fcnfg 0 0 keyacc 0 0 0 0 0 $1824 fprot fpopen fpdis fps2 fps1 fps0 0 0 0 $1825 fstat fcbef fccf fpviol faccerr 0 fblank 0 0 $1826 fcmd fcmd7 fcmd6 fcmd5 fcmd4 fcmd3 fcmd2 fcmd1 fcmd0 $1827 $182b reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 41 mc9s08rc/rd/re/rg nonvolatile flash registers, shown in table 4-4 , are located in the flash memory. these registers include an 8-byte backdoor key that optionally can be used to gain access to secure memory resources. during reset events, the contents of nvprot and nvopt in the nonvolatile register area of the flash memory are transferred into corresponding fprot and fopt working registers in the high-page registers to control security and block protection options. provided the key enable (keyen) bit is 1, the 8-byte comparison key can be used to temporarily disengage memory security. this key mechanism can be accessed only through user code running in secure memory. (a security key cannot be entered directly through background debug commands.) this security key can be disabled completely by programming the keyen bit to 0. if the security key is disabled, the only way to disengage security is by mass erasing the flash if needed (normally through the background debug interface) and verifying that flash is blank. to avoid returning to secure mode after the next reset, program the security bits (sec01:sec00) to the unsecured state (1:0). 4.3 ram the mc9s08rc/rd/re/rg includes static ram. the locations in ram below $0100 can be accessed using the more efficient direct addressing mode, and any single bit in this area can be accessed with the bit-manipulation instructions (bclr, bset, brclr, and brset). locating the most frequently accessed program variables in this area of ram is preferred. the ram retains data when the mcu is in low-power wait, stop2, or stop3 mode. at power-on or after wakeup from stop1, the contents of ram are uninitialized. ram data is unaffected by any reset provided that the supply voltage does not drop below the minimum value for ram retention. for compatibility with older m68hc05 mcus, the hcs08 resets the stack pointer to $00ff. in the mc9s08rc/rd/re/rg, it is usually best to reinitialize the stack pointer to the top of the ram so the direct page ram can be used for frequently accessed ram variables and bit-addressable program variables. include the following 2-instruction sequence in your reset initialization routine (where ramlast is equated to the highest address of the ram in the freescale-provided equate file). ldhx #ramlast+1 ;point one past ram txs ;sp<-(h:x-1) table 4-4 nonvolatile register summary address register name bit 7 654321 bit 0 $ffb0 $ffb7 nvbackkey 8-byte comparison key $ffb8 $ffbc reserved $ffbd nvprot fpopen fpdis fps2 fps1 fps0 0 0 0 $ffbe reserved $ffbf nvopt keyen fnored 0 0 0 0 sec01 sec00
memory mc9s08rc/rd/re/rg 42 freescale semiconductor when security is enabled, the ram is considered a secure memory resource and is not accessible through bdm or through code executing from non-secure memory. see 4.5 security for a detailed description of the security feature. 4.4 flash the flash memory is intended primarily for program storage. in-circuit programming allows the operating program to be loaded into the flash memory after final assembly of the application product. it is possible to program the entire array through the single-wire background debug interface. because no special voltages are needed for flash erase and programming operations, in-application programming is also possible through other software-controlled communication paths. for a more detailed discussion of in-circuit and in-application programming, refer to the hcs08 family reference manual, volume i, freescale semiconductor document order number hcs08rmv1/d. 4.4.1 features features of the flash memory include: flash size mc9s08rc/rd/re/rg60 ?63374 bytes (124 pages of 512 bytes each) mc9s08rc/rd/re/rg32 ?32768 bytes (64 pages of 512 bytes each) mc9s08rc/rd/re16 ?16384 bytes (32 pages of 512 bytes each) mc9s08rc/rd/re8 ?8192 bytes (16 pages of 512 bytes each) single power supply program and erase command interface for fast program and erase operation up to 100,000 program/erase cycles at typical voltage and temperature flexible block protection security feature for flash and ram auto power-down for low-frequency read accesses 4.4.2 program and erase times before any program or erase command can be accepted, the flash clock divider register (fcdiv) must be written to set the internal clock for the flash module to a frequency (f fclk ) between 150 khz and 200 khz (see 4.6.1 flash clock divider register (fcdiv) ). this register can be written only once, so normally this write is done during reset initialization. fcdiv cannot be written if the access error flag, faccerr in fstat, is set. the user must ensure that faccerr is not set before writing to the fcdiv register. one period of the resulting clock (1/f fclk ) is used by the command processor to time program and erase pulses. an integer number of these timing pulses are used by the command processor to complete a program or erase command.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 43 mc9s08rc/rd/re/rg table 4-5 shows program and erase times. the bus clock frequency and fcdiv determine the frequency of fclk (f fclk ). the time for one cycle of fclk is t fclk = 1/f fclk . the times are shown as a number of cycles of fclk and as an absolute time for the case where t fclk =5 s. program and erase times shown include overhead for the command state machine and enabling and disabling of program and erase voltages. 4.4.3 program and erase command execution the steps for executing any of the commands are listed below. the fcdiv register must be initialized and any error flags cleared before beginning command execution. the command execution steps are: 1. write a data value to an address in the flash array. the address and data information from this write is latched into the flash interface. this write is a required first step in any command sequence. for erase and blank check commands, the value of the data is not important. for page erase commands, the address may be any address in the 512-byte page of flash to be erased. for mass erase and blank check commands, the address can be any address in the flash memory. whole pages of 512 bytes are the smallest block of flash that may be erased. in the 60k version, there are two instances where the size of a block that is accessible to the user is less than 512 bytes: the first page following ram, and the first page following the high page registers. these pages are overlapped by the ram and high page registers respectively. 2. write the command code for the desired command to fcmd. the five valid commands are blank check ($05), byte program ($20), burst program ($25), page erase ($40), and mass erase ($41). the command code is latched into the command buffer. 3. write a 1 to the fcbef bit in fstat to clear fcbef and launch the command (including its address and data information). a partial command sequence can be aborted manually by writing a 0 to fcbef any time after the write to the memory array and before writing the 1 that clears fcbef and launches the complete command. aborting a command in this way sets the faccerr access error flag, which must be cleared before starting a new command. table 4-5 program and erase times parameter cycles of fclk time if fclk = 200 khz byte program 9 45 s byte program (burst) 4 20 s (1) notes : 1. excluding start/end overhead page erase 4000 20 ms mass erase 20,000 100 ms
memory mc9s08rc/rd/re/rg 44 freescale semiconductor a strictly monitored procedure must be adhered to, or the command will not be accepted. this minimizes the possibility of any unintended changes to the flash memory contents. the command complete flag (fccf) indicates when a command is complete. the command sequence must be completed by clearing fcbef to launch the command. figure 4-2 is a flowchart for executing all of the commands except for burst programming. the fcdiv register must be initialized before using any flash commands. this must be done only once following a reset. figure 4-2 flash program and erase flowchart start write to flash to buffer address and data write command to fcmd no yes fpvio or write 1 to fcbef to launch command and clear fcbef (2) 1 0 fccf ? error exit done (2) wait at least four cycles before checking fcbef or fccf. 0 faccerr ? clear error faccerr ? write to fcdiv (1) (1) only required once after reset.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 45 mc9s08rc/rd/re/rg 4.4.4 burst program execution the burst program command is used to program sequential bytes of data in less time than would be required using the standard program command. this is possible because the high voltage to the flash array does not need to be disabled between program operations. ordinarily, when a program or erase command is issued, an internal charge pump associated with the flash memory must be enabled to supply high voltage to the array. upon completion of the command, the charge pump is turned off. when a burst program command is issued, the charge pump is enabled and remains enabled after completion of the burst program operation if the following two conditions are met: the new burst program command has been queued before the current program operation completes. the next sequential address selects a byte on the same physical row as the current byte being programmed. a row of flash memory consists of 64 bytes. a byte within a row is selected by addresses a5 through a0. a new row begins when addresses a5 through a0 are all zero. the first byte of a series of sequential bytes being programmed in burst mode will take the same amount of time to program as a byte programmed in standard mode. subsequent bytes will program in the burst program time provided that the conditions above are met. in the case where the next sequential address is the beginning of a new row, the program time for that byte will be the standard time instead of the burst time. this is because the high voltage to the array must be disabled and then enabled again. if a new burst command has not been queued before the current command completes, then the charge pump will be disabled and high voltage removed from the array.
memory mc9s08rc/rd/re/rg 46 freescale semiconductor figure 4-3 flash burst program flowchart 1 0 fcbef ? start write to flash to buffer address and data write command to fcmd no yes fpvio or write 1 to fcbef to launch command and clear fcbef (2) no yes new burst command ? 1 0 fccf ? error exit done (2) wait at least four cycles before checking fcbef or fccf. 1 0 faccerr ? clear error faccerr ? write to fcdiv (1) (1) only required once after reset.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 47 mc9s08rc/rd/re/rg 4.4.5 access errors an access error occurs whenever the command execution protocol is violated. any of the following specific actions will cause the access error flag (faccerr) in fstat to be set. faccerr must be cleared by writing a 1 to faccerr in fstat before any command can be processed: writing to a flash address before the internal flash clock frequency has been set by writing to the fcdiv register writing to a flash address while fcbef is not set (a new command cannot be started until the command buffer is empty.) writing a second time to a flash address before launching the previous command (there is only one write to flash for every command.) writing a second time to fcmd before launching the previous command (there is only one write to fcmd for every command.) writing to any flash control register other than fcmd after writing to a flash address writing any command code other than the five allowed codes ($05, $20, $25, $40, or $41) to fcmd accessing (read or write) any flash control register other than the write to fstat (to clear fcbef and launch the command) after writing the command to fcmd the mcu enters stop mode while a program or erase command is in progress (the command is aborted.) writing the byte program, burst program, or page erase command code ($20, $25, or $40) with a background debug command while the mcu is secured (the background debug controller can only do blank check and mass erase commands when the mcu is secure.) writing 0 to fcbef to cancel a partial command 4.4.6 flash block protection block protection prevents program or erase changes for flash memory locations in a designated address range. mass erase is disabled when any block of flash is protected. the mc9s08rc/rd/re/rg allows a block of memory at the end of flash, and/or the entire flash memory to be block protected. a disable control bit and a 3-bit control field, for each of the blocks, allows the user to independently set the size of these blocks. a separate control bit allows block protection of the entire flash memory array. all seven of these control bits are located in the fprot register (see 4.6.4 flash protection register (fprot and nvprot) ). at reset, the high-page register (fprot) is loaded with the contents of the nvprot location that is in the nonvolatile register block of the flash memory. the value in fprot cannot be changed directly from application software so a runaway program cannot alter the block protection settings. if the last 512 bytes of flash (which includes the nvprot register) is protected, the application program cannot alter the block protection settings (intentionally or unintentionally). the fprot control bits can be written by background debug commands to allow a way to erase a protected flash memory.
memory mc9s08rc/rd/re/rg 48 freescale semiconductor one use for block protection is to block protect an area of flash memory for a bootloader program. this bootloader program then can be used to erase the rest of the flash memory and reprogram it. because the bootloader is protected, it remains intact even if mcu power is lost during an erase and reprogram operation. 4.4.7 vector redirection whenever any block protection is enabled, the reset and interrupt vectors will be protected. for this reason, a mechanism for redirecting vector reads is provided. vector redirection allows users to modify interrupt vector information without unprotecting bootloader and reset vector space. for redirection to occur, at least some portion but not all of the flash memory must be block protected by programming the nvprot register located at address $ffbd. all of the interrupt vectors (memory locations $ffc0?fffd) are redirected, while the reset vector ($fffe:ffff) is not. for example, if 512 bytes of flash are protected, the protected address region is from $fe00 through $ffff. the interrupt vectors ($ffc0?fffd) are redirected to the locations $fdc0?fdfd. now, if an spi interrupt is taken for instance, the values in the locations $fde0:fde1 are used for the vector instead of the values in the locations $ffe0:ffe1. this allows the user to reprogram the unprotected portion of the flash with new program code including new interrupt vector values while leaving the protected area, which includes the default vector locations, unchanged. 4.5 security the mc9s08rc/rd/re/rg includes circuitry to prevent unauthorized access to the contents of flash and ram memory. when security is engaged, flash and ram are considered secure resources. direct-page registers, high-page registers, and the background debug controller are considered unsecured resources. programs executing within secure memory have normal access to any mcu memory locations and resources. attempts to access a secure memory location with a program executing from an unsecured memory space or through the background debug interface are blocked (writes are ignored and reads return all 0s). security is engaged or disengaged based on the state of two nonvolatile register bits (sec01:sec00) in the fopt register. during reset, the contents of the nonvolatile location nvopt are copied from flash into the working fopt register in high-page register space. a user engages security by programming the nvopt location, which can be done at the same time the flash memory is programmed. the 1:0 state disengages security while the other three combinations engage security. notice the erased state (1:1) makes the mcu secure. during development, whenever the flash is erased, it is good practice to immediately program the sec00 bit to 0 in nvopt so sec01:sec00 = 1:0. this would allow the mcu to remain unsecured after a subsequent reset. the on-chip debug module cannot be enabled while the mcu is secure. the separate background debug controller can still be used for background memory access commands, but the mcu cannot enter active background mode except by holding bkgd/ms low at the rising edge of reset. a user can choose to allow or disallow a security unlocking mechanism through an 8-byte backdoor security key. if the nonvolatile keyen bit in nvopt/fopt is 0, the backdoor key is disabled and there
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 49 mc9s08rc/rd/re/rg is no way to disengage security without completely erasing all flash locations. if keyen is 1, a secure user program can temporarily disengage security by: 1. writing 1 to keyacc in the fcnfg register. this makes the flash module interpret writes to the backdoor comparison key locations (nvbackkey through nvbackkey+7) as values to be compared against the key rather than as the first step in a flash program or erase command. 2. writing the user-entered key values to the nvbackkey through nvbackkey+7 locations. these writes must be done in order starting with the value for nvbackkey and ending with nvbackkey+7. sthx must not be used for these writes because these writes cannot be done on adjacent bus cycles. user software normally would get the key codes from outside the mcu system through a communication interface such as a serial i/o. 3. writing 0 to keyacc in the fcnfg register. if the 8-byte key that was just written matches the key stored in the flash locations, sec01:sec00 are automatically changed to 1:0 and security will be disengaged until the next reset. the security key can be written only from ram, so it cannot be entered through background commands without the cooperation of a secure user program. the flash memory cannot be accessed by read operations while keyacc is set. the backdoor comparison key (nvbackkey through nvbackkey+7) is located in flash memory locations in the nonvolatile register space so users can program these locations exactly as they would program any other flash memory location. the nonvolatile registers are in the same 512-byte block of flash as the reset and interrupt vectors, so block protecting that space also block protects the backdoor comparison key. block protects cannot be changed from user application programs, so if the vector space is block protected, the backdoor security key mechanism cannot permanently change the block protect, security settings, or the backdoor key. security can always be disengaged through the background debug interface by performing these steps: 1. disable any block protections by writing fprot. fprot can be written only with background debug commands, not from application software. 2. mass erase flash if necessary. 3. blank check flash. provided flash is completely erased, security is disengaged until the next reset. to avoid returning to secure mode after the next reset, program nvopt so sec01:sec00 = 1:0. 4.6 flash registers and control bits the flash module has nine 8-bit registers in the high-page register space, three locations in the nonvolatile register space in flash memory that are copied into three corresponding high-page control registers at reset. there is also an 8-byte comparison key in flash memory. refer to table 4-3 and table 4-4 for the absolute address assignments for all flash registers. this section refers to registers and control bits only by their names. a freescale-provided equate or header file normally is used to translate these names into the appropriate absolute addresses.
memory mc9s08rc/rd/re/rg 50 freescale semiconductor 4.6.1 flash clock divider register (fcdiv) bit 7 of this register is a read-only status flag. bits 6 through 0 may be read at any time but can be written only one time. before any erase or programming operations are possible, write to this register to set the frequency of the clock for the nonvolatile memory system within acceptable limits. divld divisor loaded status flag when set, this read-only status flag indicates that the fcdiv register has been written since reset. reset clears this bit and the first write to this register causes this bit to become set regardless of the data written. 1 = fcdiv has been written since reset; erase and program operations enabled for flash. 0 = fcdiv has not been written since reset; erase and program operations disabled for flash. prdiv8 prescale (divide) flash clock by 8 1 = clock input to the flash clock divider is the bus rate clock divided by 8. 0 = clock input to the flash clock divider is the bus rate clock. div5:div0 divisor for flash clock divider the flash clock divider divides the bus rate clock (or the bus rate clock divided by 8 if prdiv8 = 1) by the value in the 6-bit div5:div0 field plus one. the resulting frequency of the internal flash clock must fall within the range of 200 khz to 150 khz for proper flash operations. program/erase timing pulses are one cycle of this internal flash clock, which corresponds to a range of 5 s to 6.7 s. the automated programming logic uses an integer number of these pulses to complete an erase or program operation. equation 1 if prdiv8 = 0 ?f fclk = f bus ([div5:div0] + 1) equation 2 if prdiv8 = 1 ?f fclk = f bus (8 ([div5:div0] + 1)) table 4-6 shows the appropriate values for prdiv8 and div5:div0 for selected bus frequencies. bit 7 6 54321 bit 0 read: divld prdiv8 div5 div4 div3 div2 div1 div0 write: reset: 0 0 000000 = unimplemented or reserved figure 4-4 flash clock divider register (fcdiv)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 51 mc9s08rc/rd/re/rg 4.6.2 flash options register (fopt and nvopt) during reset, the contents of the nonvolatile location nvopt are copied from flash into fopt. bits 5 through 2 are not used and always read 0. this register may be read at any time, but writes have no meaning or effect. to change the value in this register, erase and reprogram the nvopt location in flash memory as usual and then issue a new mcu reset. keyen backdoor key mechanism enable when this bit is 0, the backdoor key mechanism cannot be used to disengage security. the backdoor key mechanism is accessible only from user (secured) firmware. bdm commands cannot be used to write key comparison values that would unlock the backdoor key. for more detailed information about the backdoor key mechanism, refer to 4.5 security . 1 = if user firmware writes an 8-byte value that matches the nonvolatile backdoor key (nvbackkey through nvbackkey+7 in that order), security is temporarily disengaged until the next mcu reset. 0 = no backdoor key access allowed. fnored vector redirection disable when this bit is 1, then vector redirection is disabled. 1 = vector redirection disabled. 0 = vector redirection enabled. table 4-6 flash clock divider settings f bus prdiv8 (binary) div5:div0 (decimal) f fclk program/erase timing pulse (5 s min, 6.7 s max) 8 mhz 0 39 200 khz 5 s 4 mhz 0 19 200 khz 5 s 2 mhz 0 9 200 khz 5 s 1 mhz 0 4 200 khz 5 s 200 khz 0 0 200 khz 5 s 150 khz 0 0 150 khz 6.7 s bit 7 6 54321 bit 0 read: keyen fnored 0000 sec01 sec00 write: reset: this register is loaded from nonvolatile location nvopt during reset. = unimplemented or reserved figure 4-5 flash options register (fopt)
memory mc9s08rc/rd/re/rg 52 freescale semiconductor sec01:sec00 security state code this 2-bit field determines the security state of the mcu as shown in table 4-7 . when the mcu is secure, the contents of ram and flash memory cannot be accessed by instructions from any unsecured source including the background debug interface. for more detailed information about security, refer to 4.5 security . sec01:sec00 changes to 1:0 after successful backdoor key entry or a successful blank check of flash. 4.6.3 flash configuration register (fcnfg) bits 7 through 5 may be read or written at any time. bits 4 through 0 always read 0 and cannot be written. keyacc enable writing of access key this bit enables writing of the backdoor comparison key. for more detailed information about the backdoor key mechanism, refer to 4.5 security . 1 = writes to nvbackkey ($ffb0?ffb7) are interpreted as comparison key writes. reads of the flash return invalid data. 0 = writes to $ffb0?ffb7 are interpreted as the start of a flash programming or erase command. 4.6.4 flash protection register (fprot and nvprot) during reset, the contents of the nonvolatile location nvprot is copied from flash into fprot. bits 0, 1, and 2 are not used and each always reads as 0. this register may be read at any time, but user program writes have no meaning or effect. background debug commands can write to fprot at $1824. table 4-7 security states sec01:sec00 description 0:0 secure 0:1 secure 1:0 unsecured 1:1 secure bit 7 6 54321 bit 0 read: 0 0 keyacc 00000 write: reset: 0 0 000000 = unimplemented or reserved figure 4-6 flash configuration register (fcnfg)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 53 mc9s08rc/rd/re/rg figure 4-7 flash protection register (fprot) fpopen open unprotected flash for program/erase 1 = any flash location, not otherwise block protected or secured, may be erased or programmed. 0 = entire flash memory is block protected (no program or erase allowed). fpdis flash protection disable 1 = no flash block is protected. 0 = flash block specified by fps2:fps0 is block protected (program and erase not allowed). fps2:fps1:fps0 flash protect size selects when fpdis = 0, this 3-bit field determines the size of a protected block of flash locations at the high address end of the flash (see table 4-8 ). protected flash locations cannot be erased or programmed. bit 7 6 54321 bit 0 read: fpopen fpdis fps2 fps1 fps0 000 write: (1) notes : 1. background commands can be used to change the contents of these bits in fprot. (1) (1) (1) (1) reset: this register is loaded from nonvolatile location nvprot during reset. = unimplemented or reserved table 4-8 high address protected block for 32k and 60k versions fps2:fps1:fps0 protected address range protected block size redirected vectors (1) notes : 1. no redirection if fpopen = 0, or fnored = 1. 0:0:0 $fe00?ffff 512 bytes $fdc0?fdfd (2) 2. reset vector is not redirected. 0:0:1 $fc00?ffff 1 kbytes $fbc0?fbfd 0:1:0 $f800?ffff 2 kbytes $f7c0?f7fd 0:1:1 $f000?ffff 4 kbytes $efc0?effd 1:0:0 $e000?ffff 8 kbytes $dfc0?dffd 1:0:1 $c000?ffff 16 kbytes $bfc0?bffd 1:1:0 (3) 3. use for 60k version only. when protecting all of 32k version memory, use fpopen = 0. $8000?ffff 32 kbytes $7fc0?7ffd 1:1:1 (3) $8000?ffff 32 kbytes $7fc0?7ffd
memory mc9s08rc/rd/re/rg 54 freescale semiconductor 4.6.5 flash status register (fstat) bits 3, 1, and 0 always read 0 and writes have no meaning or effect. the remaining five bits are status bits that can be read at any time. writes to these bits have special meanings that are discussed in the bit descriptions. figure 4-8 flash status register (fstat) fcbef flash command buffer empty flag the fcbef bit is used to launch commands. it also indicates that the command buffer is empty so that a new command sequence can be executed when performing burst programming. the fcbef bit is cleared by writing a 1 to it or when a burst program command is transferred to the array for programming. only burst program commands can be buffered. 1 = a new burst program command may be written to the command buffer. 0 = command buffer is full (not ready for additional commands). table 4-9 high address protected block for 8k and 16k version fps2:fps1:fps0 protected address range protected block size redirected vectors (1) notes : 1. no redirection if fpopen = 0, or fnored = 1. 0:0:0 $fe00?ffff 512 bytes $fdc0?fdfd (2) 2. reset vector is not redirected. 0:0:1 $fc00?ffff 1 kbytes $fbc0?fbfd 0:1:0 $f800?ffff 2 kbytes $f7c0?f7fd 0:1:1 $f000?ffff 4 kbytes $efc0?effd 1:0:0 (3) 3. use for 60k version only. when protecting all of 32k version memory, use fpopen = 0. $e000?ffff 8 kbytes $dfc0?dffd 1:0:1 (3) $e000?ffff 8 kbytes $dfc0?dffd 1:1:0 (3) $e000?ffff 8 kbytes $dfc0?dffd 1:1:1 (3) $e000?ffff 8 kbytes $dfc0?dffd bit 7 6 54321 bit 0 read: fcbef fccf fpviol faccerr 0 fblank 00 write: reset: 1 1 000000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 55 mc9s08rc/rd/re/rg fccf flash command complete flag fccf is set automatically when the command buffer is empty and no command is being processed. fccf is cleared automatically when a new command is started (by writing 1 to fcbef to register a command). writing to fccf has no meaning or effect. 1 = all commands complete 0 = command in progress fpviol protection violation flag fpviol is set automatically when fcbef is cleared to register a command that attempts to erase or program a location in a protected block (the erroneous command is ignored). fpviol is cleared by writing a 1 to fpviol. 1 = an attempt was made to erase or program a protected location. 0 = no protection violation. faccerr access error flag faccerr is set automatically when the proper command sequence is not followed exactly (the erroneous command is ignored), if a program or erase operation is attempted before the fcdiv register has been initialized, or if the mcu enters stop while a command was in progress. for a more detailed discussion of the exact actions that are considered access errors, see 4.4.5 access errors . faccerr is cleared by writing a 1 to faccerr. writing a 0 to faccerr has no meaning or effect. 1 = an access error has occurred. 0 = no access error. fblank flash verified as all blank (erased) flag fblank is set automatically at the conclusion of a blank check command if the entire flash array was verified to be erased. fblank is cleared by clearing fcbef to write a new valid command. writing to fblank has no meaning or effect. 1 = after a blank check command is completed and fccf = 1, fblank = 1 indicates the flash array is completely erased (all $ff). 0 = after a blank check command is completed and fccf = 1, fblank = 0 indicates the flash array is not completely erased. 4.6.6 flash command register (fcmd) only four command codes are recognized in normal user modes as shown in table 4-10 . refer to 4.4.3 program and erase command execution for a detailed discussion of flash programming and erase operations. bit 7 6 54321 bit 0 read: 0 0 000000 write: fcmd7 fcmd6 fcmd5 fcmd4 fcmd3 fcmd2 fcmd1 fcmd0 reset: 0 0 000000 figure 4-9 flash command register (fcmd)
memory mc9s08rc/rd/re/rg 56 freescale semiconductor all other command codes are illegal and generate an access error. it is not necessary to perform a blank check command after a mass erase operation. only blank check is required as part of the security unlocking mechanism. table 4-10 flash commands command fcmd equate file label blank check $05 mblank byte program $20 mbyteprog byte program ?burst mode $25 mburstprog page erase (512 bytes/page) $40 mpageerase mass erase (all flash) $41 mmasserase
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 57 mc9s08rc/rd/re/rg chapter 5 resets, interrupts, and system configuration 5.1 introduction this section discusses basic reset and interrupt mechanisms and the various sources of reset and interrupts in the mc9s08rc/rd/re/rg. some interrupt sources from peripheral modules are discussed in greater detail within other sections of this data sheet. this section gathers basic information about all reset and interrupt sources in one place for easy reference. a few reset and interrupt sources, including the computer operating properly (cop) watchdog and real-time interrupt (rti), are not part of on-chip peripheral systems having their own sections but are part of the system control logic. 5.2 features reset and interrupt features include: multiple sources of reset for flexible system configuration and reliable operation: power-on detection (por) low voltage detection (lvd) with enable external reset pin with enable ( reset) cop watchdog with enable and two timeout choices illegal opcode illegal address (on 16k and 8k devices) serial command from a background debug host reset status register (srs) to indicate source of most recent reset; flag to indicate stop2 (partial power down) mode recovery (ppdf) separate interrupt vectors for each module (reduces polling overhead) (see table 5-1 )
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 58 freescale semiconductor 5.3 mcu reset resetting the mcu provides a way to start processing from a known set of initial conditions. during reset, most control and status registers are forced to initial values and the program counter is loaded from the reset vector ($fffe:$ffff). on-chip peripheral modules are disabled and i/o pins are initially configured as general-purpose high-impedance inputs with pullup devices disabled. the i bit in the condition code register (ccr) is set to block maskable interrupts until the user program has a chance to initialize the stack pointer (sp) and system control settings. sp is forced to $00ff at reset. the mc9s08rc/rd/re/rg has six sources for reset: power-on reset (por) low-voltage detect (lvd) computer operating properly (cop) timer illegal opcode detect illegal address (16k and 8k devices only) background debug forced reset the reset pin ( reset) each of these sources, with the exception of the background debug forced reset, has an associated bit in the system reset status register. whenever the mcu enters reset, the reset pin is driven low for 34 internal bus cycles where the internal bus frequency is one-half the osc frequency. after the 34 cycles are completed, the pin is released and will be pulled up by the internal pullup resistor, unless it is held low externally. after the pin is released, it is sampled after another 38 cycles to determine whether the reset pin is the cause of the mcu reset. 5.4 computer operating properly (cop) watchdog the cop watchdog is intended to force a system reset when the application software fails to execute as expected. to prevent a system reset from the cop timer (when it is enabled), application software must reset the cop timer periodically. if the application program gets lost and fails to reset the cop before it times out, a system reset is generated to force the system back to a known starting point. the cop watchdog is enabled by the cope bit in sopt (see 5.8.4 system options register (sopt) for additional information). the cop timer is reset by writing any value to the address of srs. this write does not affect the data in the read-only srs. instead, the act of writing to this address is decoded and sends a reset signal to the cop timer. after any reset, the cop timer is enabled. this provides a reliable way to detect code that is not executing as intended. if the cop watchdog is not used in an application, it can be disabled by clearing the cope bit in the write-once sopt register. also, the copt bit can be used to choose one of two timeout periods (2 18 or 2 20 cycles of the bus rate clock). even if the application will use the reset default settings in cope and copt, the user must write to write-once sopt during reset initialization to lock in the settings. that way, they cannot be changed accidentally if the application program gets lost.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 59 mc9s08rc/rd/re/rg the write to srs that services (clears) the cop timer must not be placed in an interrupt service routine (isr) because the isr could continue to be executed periodically even if the main application program fails. when the mcu is in active background mode, the cop timer is temporarily disabled. 5.5 interrupts interrupts provide a way to save the current cpu status and registers, execute an interrupt service routine (isr), and then restore the cpu status so processing resumes where it was before the interrupt. other than the software interrupt (swi), which is a program instruction, interrupts are caused by hardware events such as an edge on the irq pin or a timer-overflow event. the debug module can also generate an swi under certain circumstances. if an event occurs in an enabled interrupt source, an associated read-only status flag will become set. the cpu will not respond until and unless the local interrupt enable is a logic 1 to enable the interrupt. the i bit in the ccr is logic 0 to allow interrupts. the global interrupt mask (i bit) in the ccr is initially set after reset, which masks (prevents) all maskable interrupt sources. the user program initializes the stack pointer and performs other system setup before clearing the i bit to allow the cpu to respond to interrupts. when the cpu receives a qualified interrupt request, it completes the current instruction before responding to the interrupt. the interrupt sequence uses the same cycle-by-cycle sequence as the swi instruction and consists of: saving the cpu registers on the stack setting the i bit in the ccr to mask further interrupts fetching the interrupt vector for the highest-priority interrupt that is currently pending filling the instruction queue with the first three bytes of program information starting from the address fetched from the interrupt vector locations while the cpu is responding to the interrupt, the i bit is automatically set to avoid the possibility of another interrupt interrupting the isr itself (this is called nesting of interrupts). normally, the i bit is restored to 0 when the ccr is restored from the value stacked on entry to the isr. in rare cases, the i bit may be cleared inside an isr (after clearing the status flag that generated the interrupt) so that other interrupts can be serviced without waiting for the first service routine to finish. this practice is not recommended for anyone other than the most experienced programmers because it can lead to subtle program errors that are difficult to debug. the interrupt service routine ends with a return-from-interrupt (rti) instruction that restores the ccr, a, x, and pc registers to their pre-interrupt values by reading the previously saved information off the stack. note: for compatibility with the m68hc08 family, the h register is not automatically saved and restored. it is good programming practice to push h onto the stack at the start of the interrupt service routine (isr) and restore it just before the rti that is used to return from the isr. if two or more interrupts are pending when the i bit is cleared, the highest priority source is serviced first (see table 5-1 ).
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 60 freescale semiconductor 5.5.1 interrupt stack frame figure 5-1 shows the contents and organization of a stack frame. before the interrupt, the stack pointer (sp) points at the next available byte location on the stack. the current values of cpu registers are stored on the stack starting with the low-order byte of the program counter (pcl) and ending with the ccr. after stacking, the sp points at the next available location on the stack, which is the address that is one less than the address where the ccr was saved. the pc value that is stacked is the address of the instruction in the main program that would have executed next if the interrupt had not occurred. figure 5-1 interrupt stack frame when an rti instruction is executed, these values are recovered from the stack in reverse order. as part of the rti sequence, the cpu fills the instruction pipeline by reading three bytes of program information, starting from the pc address just recovered from the stack. the status flag causing the interrupt must be acknowledged (cleared) before returning from the isr. typically, the flag must be cleared at the beginning of the isr so that if another interrupt is generated by this same source, it will be registered so it can be serviced after completion of the current isr. condition code register accumulator index register (low byte x) program counter high * high byte (h) of index register is not automatically stacked. * program counter low 70 unstacking order stacking order 5 4 3 2 1 1 2 3 4 5 toward lower addresses toward higher addresses sp before sp after interrupt stacking the interrupt
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 61 mc9s08rc/rd/re/rg 5.5.2 external interrupt request (irq) pin external interrupts are managed by the irqsc status and control register. when the irq function is enabled, synchronous logic monitors the pin for edge-only or edge-and-level events. when the mcu is in stop mode and system clocks are shut down, a separate asynchronous path is used so the irq (if enabled) can wake the mcu. 5.5.2.1 pin configuration options the irq pin enable (irqpe) control bit in the irqsc register must be 1 in order for the irq pin to act as the interrupt request (irq) input. when the pin is configured as an irq input, the user can choose the polarity of edges or levels detected (irqedg), whether the pin detects edges-only or edges and levels (irqmod), and whether an event causes an interrupt or merely sets the irqf flag (which can be polled by software). when the irq pin is configured to detect rising edges, an optional pulldown resistor is available rather than a pullup resistor. bih and bil instructions may be used to detect the level on the irq pin when the pin is configured to act as the irq input. 5.5.2.2 edge and level sensitivity the irqmod control bit reconfigures the detection logic so it detects edge events and pin levels. in this edge detection mode, the irqf status flag becomes set when an edge is detected (when the irq pin changes from the deasserted to the asserted level), but the flag is continuously set (and cannot be cleared) as long as the irq pin remains at the asserted level. 5.5.3 interrupt vectors, sources, and local masks table 5-1 provides a summary of all interrupt sources. higher-priority sources are located towards the bottom of the table. the high-order byte of the address for the interrupt service routine is located at the first address in the vector address column, and the low-order byte of the address for the interrupt service routine is located at the next higher address. when an interrupt condition occurs, an associated flag bit becomes set. if the associated local interrupt enable is 1, an interrupt request is sent to the cpu. within the cpu, if the global interrupt mask (i bit in the ccr) is 0, the cpu will finish the current instruction; stack the pcl, pch, x, a, and ccr cpu registers; set the i bit; and then fetch the interrupt vector for the highest priority pending interrupt. processing then continues in the interrupt service routine.
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 62 freescale semiconductor 5.6 low-voltage detect (lvd) system the mc9s08rc/rd/re/rg includes a system to protect against low-voltage conditions in order to protect memory contents and control mcu system states during supply voltage variations. the system is comprised of a power-on reset (por) circuit, an lvd circuit with flag bits for warning and detection, and a mechanism for entering a system safe state following an lvd interrupt. the lvd circuit can be configured to generate an interrupt or a reset when low supply voltage has been detected. table 5-1 vector summary vector priority vector number address (high/low) vector name module source enable description lower higher 16 through 31 $ffc0/ffc1 through $ffde/ffdf unused vector space (available for user program) 15 $ffe0/ffe1 vspi1 spi (1) notes : 1. the spi module is not included on the mc9s08rc/rd/re devices. this vector location is unused for those devices. spif modf sptef spie spie sptie spi 14 $ffe2/ffe3 vrti system control rtif rtie real-time interrupt 13 $ffe4/ffe5 vkeyboard2 kbi2 kbf kbie keyboard 2 pins 12 $ffe6/ffe7 vkeyboard1 kbi1 kbf kbie keyboard 1 pins 11 $ffe8/ffe9 vacmp1 acmp (2) 2. the analog comparator (acmp) module is not included on the mc9s08rd devices. this vector location is unused for those devices. acf acie acmp compare 10 $ffea/ffeb vcmt cmt eocf eocie cmt 9 $ffec/ffed vsci1tx sci (3) 3. the sci module is not included on the mc9s08rc devices. this vector location is unused for those devices. tdre tc tie tcie sci transmit 8 $ffee/ffef vsci1rx sci (3) idle rdrf ilie rie sci receive 7 $fff0/fff1 vsci1err sci (3) or nf fe pf orie nfie feie pfie sci error 6 $fff2/fff3 vtpm1ovf tpm tof toie tpm over?w 5 $fff4/fff5 vtpm1ch1 tpm ch1f ch1ie tpm channel 1 4 $fff6/fff7 vtpm1ch0 tpm ch0f ch0ie tpm channel 0 3 $fff8/fff9 virq irq irqf irqie irq pin 2 $fffa/fffb vlvd system control lvdf lvdie low-voltage detect 1 $fffc/fffd vswi core swi instruction software interrupt 0 $fffe/ffff vreset system control cop lv d reset pin illegal opcode illegal address cope lvdre rstpe watchdog timer low-voltage detect external pin illegal opcode illegal address
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 63 mc9s08rc/rd/re/rg 5.6.1 power-on reset operation when power is initially applied to the mcu, or when the supply voltage drops below the v por level, the por circuit will cause a reset condition. as the supply voltage rises, the lvd circuit will hold the chip in reset until the supply has risen above the v lvd level. both the por bit and the lvd bit in srs are set following a por. 5.6.2 lvd reset operation the lvd can be configured to generate a reset upon detection of a low voltage condition. this is done by setting lvdre to 1. lvdre is a write-once bit that is set following a por and is unaffected by other resets. when lvdre = 1, setting the safe bit has no effect. after an lvd reset has occurred, the lvd system will hold the mcu in reset until the supply voltage is above the v lvd level. the lvd bit in the srs register is set following either an lvd reset or por. 5.6.3 lvd interrupt and safe state operation when the voltage on the supply pin v dd drops below v lvd and the lvd circuit is configured for interrupt operation (lvdie is set and lvdre is clear), an lvd interrupt will occur. the lvd trip point is set above the minimum voltage at which the mcu can reliably operate, but the supply voltage may still be dropping. it is recommended that the user place the mcu in the safe state as soon as possible following a lvd interrupt. for systems where the supply voltage may drop so rapidly that the mcu may not have time to service the lvd interrupt and enter the safe state, it is recommended that the lvd be configured to generate a reset. the safe state is entered by executing a stop instruction with the safe bit in the system power management status and control 1 (spmsc1) register set while in a low voltage condition (lvdf = 1). after the lvd interrupt has occurred, the user may configure the system to block all interrupts, resets, or wakeups by writing a 1 to the safe bit. while safe =1 and v dd is below v rearm all interrupts, resets, and wakeups are blocked. after v dd is above v rearm , the safe bit is ignored (the safe bit will still read a logic 1). after setting the safe bit, the mcu must be put into either the stop3 or stop2 mode before the supply voltage drops below the minimum operating voltage of the mcu. the supply voltage may now drop to a level just above the por trip point and then restored to a level above v rearm and the mcu state (in the case of stop3) and ram contents will be preserved. when the supply voltage has been restored, interrupts, resets, and wakeups are then unblocked. when the mcu has recovered from stop mode, the safe bit should be cleared. 5.6.4 low-voltage warning (lvw) the lvd system has a low-voltage warning flag to indicate to the user that the supply voltage is approaching, but is still above, the low-voltage detect voltage. the lvw does not have an interrupt associated with it. however, the flash memory cannot be reliably programmed or erased below the v lvw level, so the status of the lvwf bit in the system power management status and control 2 (spmsc2) register must be checked before initiating any flash program or erase operation.
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 64 freescale semiconductor 5.7 real-time interrupt (rti) the real-time interrupt (rti) function can be used to generate periodic interrupts based on a divide of the external oscillator or an internal 1-khz clock source. it can also be used to wake the mcu from stop2 or stop3 mode when using the internal 1-khz clock source. the srtisc register includes a read-only status flag, a write-only acknowledge bit, and a 3-bit control value (rtis2:rtis1:rtis0) used to disable the clock source to the real-time interrupt or select one of seven wakeup delays between 8 ms and 1.024 seconds. the 1-khz clock source and therefore the periodic rates have a tolerance of about 30 percent. the rti has a local interrupt enable, rtie, to allow masking of the real-time interrupt. it can be disabled by writing 0:0:0 to rtis2:rtis1:rtis0 so the clock source is disabled and no interrupts will be generated. see 5.8.6 system real-time interrupt status and control register (srtisc) for detailed information about this register. 5.8 reset, interrupt, and system control registers and control bits one 8-bit register in the direct page register space and five 8-bit registers in the high-page register space are related to reset and interrupt systems. refer to the direct-page register summary in the memory section of this data sheet for the absolute address assignments for all registers. this section refers to registers and control bits only by their names. a freescale-provided equate or header file is used to translate these names into the appropriate absolute addresses. some control bits in the sopt and spmsc2 registers are related to modes of operation. although brief descriptions of these bits are provided here, the related functions are discussed in greater detail in modes of operation . 5.8.1 interrupt pin request status and control register (irqsc) this direct page register includes two unimplemented bits that always read 0, four read/write bits, one read-only status bit, and one write-only bit. these bits are used to configure the irq function, report status, and acknowledge irq events. figure 5-2 interrupt request status and control register (irqsc) bit 7 654321 bit 0 read: 0 0 irqedg irqpe irqf 0 irqie irqmod write: irqack reset: 00000000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 65 mc9s08rc/rd/re/rg irqedg interrupt request (irq) edge select this read/write control bit is used to select the polarity of edges or levels on the irq pin that cause irqf to be set. the irqmod control bit determines whether the irq pin is sensitive to both edges and levels or only edges. when the irq pin is enabled as the irq input and is configured to detect rising edges, the optional pullup resistor is reconfigured as an optional pulldown resistor. 1 = irq is rising edge or rising edge/high-level sensitive. 0 = irq is falling edge or falling edge/low-level sensitive. irqpe irq pin enable this read/write control bit enables the irq pin function. when this bit is set the irq pin can be used as an interrupt request. also, when this bit is set, either an internal pull-up or an internal pull-down resistor is enabled depending on the state of the irqmod bit. 1 = irq pin function is enabled. 0 = irq pin function is disabled. irqf irq flag this read-only status bit indicates when an interrupt request event has occurred. 1 = irq event detected. 0 = no irq request. irqack irq acknowledge this write-only bit is used to acknowledge interrupt request events (write 1 to clear irqf). writing 0 has no meaning or effect. reads always return logic 0. if edge-and-level detection is selected (irqmod = 1), irqf cannot be cleared while the irq pin remains at its asserted level. irqie irq interrupt enable this read/write control bit determines whether irq events generate a hardware interrupt request. 1 = hardware interrupt requested whenever irqf = 1. 0 = hardware interrupt requests from irqf disabled (use polling). irqmod irq detection mode this read/write control bit selects either edge-only detection or edge-and-level detection. the irqedg control bit determines the polarity of edges and levels that are detected as interrupt request events. see 5.5.2.2 edge and level sensitivity for more details. 1 = irq event on falling edges and low levels or on rising edges and high levels. 0 = irq event on falling edges or rising edges only. 5.8.2 system reset status register (srs) this register includes seven read-only status flags to indicate the source of the most recent reset. when a debug host forces reset by writing 1 to bdfr in the sbdfr register, none of the status bits in srs will be set. writing any value to this register address clears the cop watchdog timer without affecting the contents of this register. the reset state of these bits depends on what caused the mcu to reset.
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 66 freescale semiconductor figure 5-3 system reset status (srs) por power-on reset reset was caused by the power-on detection logic. because the internal supply voltage was ramping up at the time, the low-voltage reset (lvr) status bit is also set to indicate that the reset occurred while the internal supply was below the lvr threshold. 1 = por caused reset. 0 = reset not caused by por. pin external reset pin reset was caused by an active-low level on the external reset pin. 1 = reset came from external reset pin. 0 = reset not caused by external reset pin. cop computer operating properly (cop) watchdog reset was caused by the cop watchdog timer timing out. this reset source may be blocked by cope = 0. 1 = reset caused by cop timeout. 0 = reset not caused by cop timeout. ilop illegal opcode reset was caused by an attempt to execute an unimplemented or illegal opcode. the stop instruction is considered illegal if stop is disabled by stope = 0 in the sopt register. the bgnd instruction is considered illegal if active background mode is disabled by enbdm = 0 in the bdcsc register. 1 = reset caused by an illegal opcode. 0 = reset not caused by an illegal opcode. ilad illegal address access reset was caused by an attempt to access a designated illegal address. 1 = reset caused by an illegal address access 0 = reset not caused by an illegal address access bit 7 6 54321 bit 0 read: por pin cop ilop ilad (1) notes : 1. the ilad bit is only present in 16k and 8k versions of the devices. 0 lvd 0 write: writing any value to srs address clears cop watchdog timer. power-on reset: 1 0 000010 low-voltage reset: u 0 000010 any other reset: 0 (2) 2. any of these reset sources that are active at the time of reset will cause the corresponding bit(s) to be set; bits corresponding to sources that are not active at the time of reset will be cleared. (2) (2) (2) 000 u = unaffected by reset
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 67 mc9s08rc/rd/re/rg illegal address areas only exist in the 16k and 8k versions and are defined as: $0440?17ff ?gap from end of ram to start of high-page registers $1834?bfff ?gap from end of high-page registers to start of flash memory unused and reserved locations in register areas are not considered designated illegal addresses and do not trigger illegal address resets. lvd low voltage detect if the lvdre bit is set and the supply drops below the lvd trip voltage, an lvd reset occurs. this bit is also set by por. 1 = reset caused by lvd trip or por 0 = reset not caused by lvd trip or por 5.8.3 system background debug force reset register (sbdfr) this register contains a single write-only control bit. a serial background command such as write_byte must be used to write to sbdfr. attempts to write this register from a user program are ignored. reads always return $00. figure 5-4 system background debug force reset register (sbdfr) bdfr background debug force reset a serial background command such as write_byte may be used to allow an external debug host to force a target system reset. writing logic 1 to this bit forces an mcu reset. this bit cannot be written from a user program. 5.8.4 system options register (sopt) this register may be read at any time. bits 3 and 2 are unimplemented and always read 0. this is a write-once register so only the first write after reset is honored. any subsequent attempt to write to sopt (intentionally or unintentionally) is ignored to avoid accidental changes to these sensitive settings. sopt must be written during the user? reset initialization program to set the desired controls even if the desired settings are the same as the reset settings. bit 7 654321 bit 0 read: 00000000 write: bdfr (1) notes : 1. bdfr is writable only through serial background debug commands, not from user programs. reset: 00000000 = unimplemented or reserved
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 68 freescale semiconductor cope cop watchdog enable this write-once bit defaults to 1 after reset. 1 = cop watchdog timer enabled (force reset on timeout). 0 = cop watchdog timer disabled. copt cop watchdog timeout this write-once bit defaults to 1 after reset. 1 = long timeout period selected (2 20 cycles of busclk). 0 = short timeout period selected (2 18 cycles of busclk). stope stop mode enable this write-once bit defaults to 0 after reset, which disables stop mode. if stop mode is disabled and a user program attempts to execute a stop instruction, an illegal opcode reset is forced. 1 = stop mode enabled. 0 = stop mode disabled. bkgdpe background debug mode pin enable the bkgdpe bit enables the ptd0/bkgd/ms pin to function as bkgd/ms. when the bit is clear, the pin will function as ptd0, which is an output only general purpose i/o. this pin always defaults to bkgd/ms function after any reset. 1 = bkgd pin enabled. 0 = bkgd pin disabled. rstpe reset pin enable the rstpe bit enables the ptd1/ reset pin to function as reset. when the bit is clear, the pin will function as ptd1, which is an output only general purpose i/o. this pin always defaults to reset function after any reset. 1 = reset pin enabled 0 = reset pin disabled bit 7 654321 bit 0 read: cope copt stope 00 bkgdpe rstpe write: reset: 11010011 = unimplemented or reserved figure 5-5 system options register (sopt)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 69 mc9s08rc/rd/re/rg 5.8.5 system device identification register (sdidh, sdidl) this read-only register is included so host development systems can identify the hcs08 derivative and revision number. this allows the development software to recognize where specific memory blocks, registers, and control bits are located in a target mcu. figure 5-6 system device identification register (sdidh, sdidl) rev[3:0] revision number the high-order 4 bits of address $1806 are hard coded to reflect the current mask set revision number (0?). id[11:0] part identification number each derivative in the hcs08 family has a unique identification number. the mc9s08rc/rd/re/rg32/60 is hard coded to the value $004 and the mc9s08rc/rd/re8/16 is hard coded to the value $003. 5.8.6 system real-time interrupt status and control register (srtisc) this register contains one read-only status flag, one write-only acknowledge bit, three read/write delay selects, and three unimplemented bits, which always read 0. figure 5-7 system rti status and control register (srtisc) bit 7 6 5 4321 bit 0 read: rev3 rev2 rev1 rev0 id11 id10 id9 id8 reset: 0 (1) notes : 1. the revision number that is hard coded into these bits reflects the current silicon revision level. 0 (1) 0 (1) 0 (1) 0000 read: id7 id6 id5 id4 id3 id2 id1 id0 reset, 8/16k: 0 0 0 00011 reset, 32/60k: 0 0 0 00100 = unimplemented or reserved bit 7 6 5 4321 bit 0 read: rtif 0 rticlks rtie 0 rtis2 rtis1 rtis0 write: rtiack reset: 0 0 0 00000 = unimplemented or reserved
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 70 freescale semiconductor rtif real-time interrupt flag this read-only status bit indicates the periodic wakeup timer has timed out. 1 = periodic wakeup timer timed out. 0 = periodic wakeup timer not timed out. rtiack real-time interrupt acknowledge this write-only bit is used to acknowledge real-time interrupt request (write 1 to clear rtif). writing 0 has no meaning or effect. reads always return logic 0. rticlks real-time interrupt clock select this read/write bit selects the clock source for the real-time interrupt. 1 = real-time interrupt request clock source is external clock. 0 = real-time interrupt request clock source is internal 1-khz oscillator. rtie real-time interrupt enable this read-write bit enables real-time interrupts. 1 = real-time interrupts enabled. 0 = real-time interrupts disabled. rtis2:rtis1:rtis0 real-time interrupt delay selects these read/write bits select the wakeup delay for the rti. the clock source for the real-time interrupt is a self-clocked source that oscillates at about 1 khz and is independent of other mcu clock sources. using an external clock source, the delays will be crystal frequency divided by the value in rtis2:rtis1:rtis0. table 5-2 real-time interrupt frequency rtis2:rtis1:rtis0 1-khz clock source delay (1) notes : 1. normal values are shown in this column based on f rti = 1 khz. see table c-9 control timing f rti for the tolerance on these values. using external clock source delay (crystal frequency) 0:0:0 disable periodic wakeup timer disable periodic wakeup timer 0:0:1 8 ms divide by 256 0:1:0 32 ms divide by 1024 0:1:1 64 ms divide by 2048 1:0:0 128 ms divide by 4096 1:0:1 256 ms divide by 8192 1:1:0 512 ms divide by 16384 1:1:1 1.024 s divide by 32768
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 71 mc9s08rc/rd/re/rg 5.8.7 system power management status and control 1 register (spmsc1) figure 5-8 system power management status and control 1 register (spmsc1) lvdf low-voltage detect flag provided lvde = 1, this read-only status bit indicates a low-voltage detect error. lvdack low-voltage detect acknowledge this write-only bit is used to acknowledge low voltage detection errors (write 1 to clear lvdf). reads always return logic 0. lvdie low-voltage detect interrupt enable this read/write bit enables hardware interrupt requests for lvdf. 1 = request a hardware interrupt when lvdf = 1. 0 = hardware interrupt disabled (use polling). safe safe system from interrupts this read/write bit enables hardware to block interrupts and resets from waking the mcu from stop mode while the supply voltage v dd is below the v rearm voltage. for a more detailed description see section 5.6.3 lvd interrupt and safe state operation . 1 = interrupts and resets are blocked while supply voltage is below re-arm voltage 0 = enable pending interrupts and resets lvdre low-voltage detect reset enable this bit enables the lvd reset function. this bit can be written only once after a reset and additional writes have no meaning or effect. it is set following a por and is unaffected by any other resets, including an lvd reset. 1 = force an mcu reset when lvdf = 1. 0 = lvdf does not generate hardware resets. bit 7 6 54321 bit 0 read: lvdf 0 lvdie safe (1) notes : 1. this bit can be written only one time after reset. additional writes are ignored. lvdre (1) 000 write: lvdack power-on reset: 0 0 001000 any other reset: 0 0 0 0 u 0 0 0 = unimplemented or reserved u = unaffected by reset
resets, interrupts, and system configuration mc9s08rc/rd/re/rg 72 freescale semiconductor 5.8.8 system power management status and control 2 register (spmsc2) this register is used to report the status of the low voltage warning function, and to configure the stop mode behavior of the mcu. figure 5-9 system power management status and control 2 register (spmsc2) lvwf low-voltage warning flag the lvwf bit indicates the low voltage warning status. 1 = low voltage warning is present or was present. 0 = low voltage warning not present. lvwack low-voltage warning acknowledge the lvwf bit indicates the low voltage warning status. writing a logic 1 to lvwack clears lvwf to a logic 0 if a low voltage warning is not present. ppdf partial power down flag the ppdf bit indicates that the mcu has exited the stop2 mode. 1 = stop2 mode recovery. 0 = not stop2 mode recovery. ppdack partial power down acknowledge writing a logic 1 to ppdack clears the ppdf bit. pdc power down control the write-once pdc bit controls entry into the power down (stop2 and stop1) modes. 1 = power down modes are enabled. 0 = power down modes are disabled. ppdc partial power down control the write-once ppdc bit controls which power down mode, stop1 or stop2, is selected. 1 = stop2, partial power down, mode enabled if pdc set. 0 = stop1, full power down, mode enabled if pdc set. bit 7 6 54321 bit 0 read: lvwf 000 ppdf 0 pdc ppdc write: lvwack ppdack reset: 0 (1) notes : 1. lvwf will be set in the case when v supply transitions below the trip point or after reset and v supply is already below v lvw . 0 00 0000 = unimplemented or reserved u = unaffected by reset
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 73 mc9s08rc/rd/re/rg chapter 6 central processor unit (cpu) 6.1 introduction this section provides summary information about the registers, addressing modes, and instruction set of the cpu of the hcs08 family. for a more detailed discussion, refer to the hcs08 family reference manual, freescale semiconductor document order number hcs08rmv1/d. the hcs08 cpu is fully source- and object-code-compatible with the m68hc08 cpu. several instructions and enhanced addressing modes were added to improve c compiler efficiency and to support a new background debug system that replaces the monitor mode of earlier m68hc08 microcontrollers (mcu).
central processor unit (cpu) mc9s08rc/rd/re/rg 74 freescale semiconductor 6.2 features features of the hcs08 cpu include: object code fully upward-compatible with m68hc05 and m68hc08 families all registers and memory are mapped to a single 64-kbyte address space 16-bit stack pointer (any size stack anywhere in 64-kbyte address space) 16-bit index register (h:x) with powerful indexed addressing modes 8-bit accumulator (a) many instructions treat x as a second general-purpose 8-bit register seven addressing modes: inherent ?operands in internal registers relative ?8-bit signed offset to branch destination immediate ?operand in next object code byte(s) direct ?operand in memory at $0000?00ff extended ?operand anywhere in 64-kbyte address space indexed relative to h:x ?five submodes including auto increment indexed relative to sp ?improves c efficiency dramatically memory-to-memory data move instructions with four address mode combinations overflow, half-carry, negative, zero, and carry condition codes support conditional branching on the results of signed, unsigned, and binary-coded decimal (bcd) operations efficient bit manipulation instructions fast 8-bit by 8-bit multiply and 16-bit by 8-bit divide instructions stop and wait instructions to invoke low-power operating modes 6.3 programmer? model and cpu registers figure 6-1 shows the five cpu registers. cpu registers are not part of the memory map.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 75 mc9s08rc/rd/re/rg figure 6-1 cpu registers 6.3.1 accumulator (a) the a accumulator is a general-purpose 8-bit register. one operand input to the arithmetic logic unit (alu) is connected to the accumulator and the alu results are often stored into the a accumulator after arithmetic and logical operations. the accumulator can be loaded from memory using various addressing modes to specify the address where the loaded data comes from, or the contents of a can be stored to memory using various addressing modes to specify the address where data from a will be stored. reset has no effect on the contents of the a accumulator. 6.3.2 index register (h:x) this 16-bit register is actually two separate 8-bit registers (h and x), which often work together as a 16-bit address pointer where h holds the upper byte of an address and x holds the lower byte of the address. all indexed addressing mode instructions use the full 16-bit value in h:x as an index reference pointer; however, for compatibility with the earlier m68hc05 family, some instructions operate only on the low-order 8-bit half (x). many instructions treat x as a second general-purpose 8-bit register that can be used to hold 8-bit data values. x can be cleared, incremented, decremented, complemented, negated, shifted, or rotated. transfer instructions allow data to be transferred from a or transferred to a where arithmetic and logical operations can then be performed. for compatibility with the earlier m68hc05 family, h is forced to $00 during reset. reset has no effect on the contents of x. sp pc condition code register carry zero negative interrupt mask half-carry (from bit 3) two? complement overflow h x 0 0 0 7 15 15 70 accumulator a index register (low) index register (high) stack pointer 87 program counter 16-bit index register h:x ccr c v11hinz
central processor unit (cpu) mc9s08rc/rd/re/rg 76 freescale semiconductor 6.3.3 stack pointer (sp) this 16-bit address pointer register points at the next available location on the automatic last-in-first-out (lifo) stack. the stack may be located anywhere in the 64-kbyte address space that has ram and can be any size up to the amount of available ram. the stack is used to automatically save the return address for subroutine calls, the return address and cpu registers during interrupts, and for local variables. the ais (add immediate to stack pointer) instruction adds an 8-bit signed immediate value to sp. this is most often used to allocate or deallocate space for local variables on the stack. sp is forced to $00ff at reset for compatibility with the earlier m68hc05 family. hcs08 programs normally change the value in sp to the address of the last location (highest address) in on-chip ram during reset initialization to free up direct page ram (from the end of the on-chip registers to $00ff). the rsp (reset stack pointer) instruction was included for compatibility with the m68hc05 family and is seldom used in new hcs08 programs because it only affects the low-order half of the stack pointer. 6.3.4 program counter (pc) the program counter is a 16-bit register that contains the address of the next instruction or operand to be fetched. during normal program execution, the program counter automatically increments to the next sequential memory location every time an instruction or operand is fetched. jump, branch, interrupt, and return operations load the program counter with an address other than that of the next sequential location. this is called a change-of-flow. during reset, the program counter is loaded with the reset vector that is located at $fffe and $ffff. the vector stored there is the address of the first instruction that will be executed after exiting the reset state. 6.3.5 condition code register (ccr) the 8-bit condition code register contains the interrupt mask (i) and five flags that indicate the results of the instruction just executed. bits 6 and 5 are set permanently to logic 1. the following paragraphs describe the functions of the condition code bits in general terms. for a more detailed explanation of how each instruction sets the ccr bits, refer to the hcs08 family reference manual, volume 1, freescale semiconductor document order number hcs08rmv1/d. figure 6-2 condition code register condition code register carry zero negative interrupt mask half-carry (from bit 3) two? complement overflow 70 ccr c v11hinz
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 77 mc9s08rc/rd/re/rg v two? complement overflow flag the cpu sets the overflow flag when a two? complement overflow occurs. the signed branch instructions bgt, bge, ble, and blt use the overflow flag. 1 = overflow 0 = no overflow h half-carry flag the cpu sets the half-carry flag when a carry occurs between accumulator bits 3 and 4 during an add-without-carry (add) or add-with-carry (adc) operation. the half-carry flag is required for binary-coded decimal (bcd) arithmetic operations. the daa instruction uses the states of the h and c condition code bits to automatically add a correction value to the result from a previous add or adc on bcd operands to correct the result to a valid bcd value. 1 = carry between bits 3 and 4 0 = no carry between bits 3 and 4 i interrupt mask bit when the interrupt mask is set, all maskable cpu interrupts are disabled. cpu interrupts are enabled when the interrupt mask is cleared. when a cpu interrupt occurs, the interrupt mask is set automatically after the cpu registers are saved on the stack, but before the first instruction of the interrupt service routine is executed. 1 = interrupts disabled 0 = interrupts enabled interrupts are not recognized at the instruction boundary after any instruction that clears i (cli or tap). this ensures that the next instruction after a cli or tap will always be executed without the possibility of an intervening interrupt, provided i was set. n negative flag the cpu sets the negative flag when an arithmetic operation, logic operation, or data manipulation produces a negative result, setting bit 7 of the result. simply loading or storing an 8-bit or 16-bit value causes n to be set if the most significant bit of the loaded or stored value was 1. 1 = negative result 0 = non-negative result z zero flag the cpu sets the zero flag when an arithmetic operation, logic operation, or data manipulation produces a result of $00 or $0000. simply loading or storing an 8-bit or 16-bit value causes z to be set if the loaded or stored value was all 0s. 1 = zero result 0 = non-zero result c carry/borrow flag the cpu sets the carry/borrow flag when an addition operation produces a carry out of bit 7 of the accumulator or when a subtraction operation requires a borrow. some instructions ?such as bit test and branch, shift, and rotate ?also clear or set the carry/borrow flag. 1 = carry out of bit 7 0 = no carry out of bit 7
central processor unit (cpu) mc9s08rc/rd/re/rg 78 freescale semiconductor 6.4 addressing modes addressing modes define the way the cpu accesses operands and data. in the hcs08, all memory, status and control registers, and input/output (i/o) ports share a single 64-kbyte linear address space so a 16-bit binary address can uniquely identify any memory location. this arrangement means that the same instructions that access variables in ram can also be used to access i/o and control registers or nonvolatile program space. some instructions use more than one addressing mode. for instance, move instructions use one addressing mode to specify the source operand and a second addressing mode to specify the destination address. instructions such as brclr, brset, cbeq, and dbnz use one addressing mode to specify the location of an operand for a test and then use relative addressing mode to specify the branch destination address when the tested condition is true. for brclr, brset, cbeq, and dbnz, the addressing mode listed in the instruction set tables is the addressing mode needed to access the operand to be tested, and relative addressing mode is implied for the branch destination. 6.4.1 inherent addressing mode (inh) in this addressing mode, operands needed to complete the instruction (if any) are located within cpu registers so the cpu does not need to access memory to get any operands. 6.4.2 relative addressing mode (rel) relative addressing mode is used to specify the destination location for branch instructions. a signed 8-bit offset value is located in the memory location immediately following the opcode. during execution, if the branch condition is true, the signed offset is sign-extended to a 16-bit value and is added to the current contents of the program counter, which causes program execution to continue at the branch destination address. 6.4.3 immediate addressing mode (imm) in immediate addressing mode, the operand needed to complete the instruction is included in the object code immediately following the instruction opcode in memory. in the case of a 16-bit immediate operand, the high-order byte is located in the next memory location after the opcode, and the low-order byte is located in the next memory location after that. 6.4.4 direct addressing mode (dir) in direct addressing mode, the instruction includes the low-order eight bits of an address in the direct page ($0000?00ff). during execution a 16-bit address is formed by concatenating an implied $00 for the high-order half of the address and the direct address from the instruction to get the 16-bit address where the desired operand is located. this is faster and more memory efficient than specifying a complete 16-bit address for the operand.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 79 mc9s08rc/rd/re/rg 6.4.5 extended addressing mode (ext) in extended addressing mode, the full 16-bit address of the operand is located in the next two bytes of program memory after the opcode (high byte first). 6.4.6 indexed addressing mode indexed addressing mode has seven variations including five that use the 16-bit h:x index register pair and two that use the stack pointer as the base reference. 6.4.6.1 indexed, no offset (ix) this variation of indexed addressing uses the 16-bit value in the h:x index register pair as the address of the operand needed to complete the instruction. 6.4.6.2 indexed, no offset with post increment (ix+) this variation of indexed addressing uses the 16-bit value in the h:x index register pair as the address of the operand needed to complete the instruction. the index register pair is then incremented (h:x = h:x + $0001) after the operand has been fetched. this addressing mode is only used for mov and cbeq instructions. 6.4.6.3 indexed, 8-bit offset (ix1) this variation of indexed addressing uses the 16-bit value in the h:x index register pair plus an unsigned 8-bit offset included in the instruction as the address of the operand needed to complete the instruction. 6.4.6.4 indexed, 8-bit offset with post increment (ix1+) this variation of indexed addressing uses the 16-bit value in the h:x index register pair plus an unsigned 8-bit offset included in the instruction as the address of the operand needed to complete the instruction. the index register pair is then incremented (h:x = h:x + $0001) after the operand has been fetched. this addressing mode is used only for the cbeq instruction. 6.4.6.5 indexed, 16-bit offset (ix2) this variation of indexed addressing uses the 16-bit value in the h:x index register pair plus a 16-bit offset included in the instruction as the address of the operand needed to complete the instruction. 6.4.6.6 sp-relative, 8-bit offset (sp1) this variation of indexed addressing uses the 16-bit value in the stack pointer (sp) plus an unsigned 8-bit offset included in the instruction as the address of the operand needed to complete the instruction. 6.4.6.7 sp-relative, 16-bit offset (sp2) this variation of indexed addressing uses the 16-bit value in the stack pointer (sp) plus a 16-bit offset included in the instruction as the address of the operand needed to complete the instruction.
central processor unit (cpu) mc9s08rc/rd/re/rg 80 freescale semiconductor 6.5 special operations the cpu performs a few special operations that are similar to instructions but do not have opcodes like other cpu instructions. in addition, a few instructions such as stop and wait directly affect other mcu circuitry. this section provides additional information about these operations. 6.5.1 reset sequence reset can be caused by a power-on-reset (por) event, internal conditions such as the cop (computer operating properly) watchdog, or by assertion of an external active-low reset pin. when a reset event occurs, the cpu immediately stops whatever it is doing (the mcu does not wait for an instruction boundary before responding to a reset event). for a more detailed discussion about how the mcu recognizes resets and determines the source, refer to the resets, interrupts, and system configuration section. the reset event is considered concluded when the sequence to determine whether the reset came from an internal source is done and when the reset pin is no longer asserted. at the conclusion of a reset event, the cpu performs a 6-cycle sequence to fetch the reset vector from $fffe and $ffff and to fill the instruction queue in preparation for execution of the first program instruction. 6.5.2 interrupt sequence when an interrupt is requested, the cpu completes the current instruction before responding to the interrupt. at this point, the program counter is pointing at the start of the next instruction, which is where the cpu should return after servicing the interrupt. the cpu responds to an interrupt by performing the same sequence of operations as for a software interrupt (swi) instruction, except the address used for the vector fetch is determined by the highest priority interrupt that is pending when the interrupt sequence started. the cpu sequence for an interrupt is: 1. store the contents of pcl, pch, x, a, and ccr on the stack, in that order. 2. set the i bit in the ccr. 3. fetch the high-order half of the interrupt vector. 4. fetch the low-order half of the interrupt vector. 5. delay for one free bus cycle. 6. fetch three bytes of program information starting at the address indicated by the interrupt vector to fill the instruction queue in preparation for execution of the first instruction in the interrupt service routine. after the ccr contents are pushed onto the stack, the i bit in the ccr is set to prevent other interrupts while in the interrupt service routine. although it is possible to clear the i bit with an instruction in the interrupt service routine, this would allow nesting of interrupts (which is not recommended because it leads to programs that are difficult to debug and maintain).
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 81 mc9s08rc/rd/re/rg for compatibility with the earlier m68hc05 mcus, the high-order half of the h:x index register pair (h) is not saved on the stack as part of the interrupt sequence. the user must use a pshh instruction at the beginning of the service routine to save h and then use a pulh instruction just before the rti that ends the interrupt service routine. it is not necessary to save h if you are certain that the interrupt service routine does not use any instructions or auto-increment addressing modes that might change the value of h. the software interrupt (swi) instruction is like a hardware interrupt except that it is not masked by the global i bit in the ccr and it is associated with an instruction opcode within the program so it is not asynchronous to program execution. 6.5.3 wait mode operation the wait instruction enables interrupts by clearing the i bit in the ccr. it then halts the clocks to the cpu to reduce overall power consumption while the cpu is waiting for the interrupt or reset event that will wake the cpu from wait mode. when an interrupt or reset event occurs, the cpu clocks will resume and the interrupt or reset event will be processed normally. if a serial background command is issued to the mcu through the background debug interface while the cpu is in wait mode, cpu clocks will resume and the cpu will enter active background mode where other serial background commands can be processed. this ensures that a host development system can still gain access to a target mcu even if it is in wait mode. 6.5.4 stop mode operation usually, all system clocks, including the crystal oscillator (when used), are halted during stop mode to minimize power consumption. in such systems, external circuitry is needed to control the time spent in stop mode and to issue a signal to wake up the target mcu when it is time to resume processing. unlike the earlier m68hc05 and m68hc08 mcus, the hcs08 can be configured to keep a minimum set of clocks running in stop mode. this optionally allows an internal periodic signal to wake the target mcu from stop mode. when a host debug system is connected to the background debug pin (bkgd) and the enbdm control bit has been set by a serial command through the background interface (or because the mcu was reset into active background mode), the oscillator is forced to remain active when the mcu enters stop mode. in this case, if a serial background command is issued to the mcu through the background debug interface while the cpu is in stop mode, cpu clocks will resume and the cpu will enter active background mode where other serial background commands can be processed. this ensures that a host development system can still gain access to a target mcu even if it is in stop mode. recovery from stop mode depends on the particular hcs08 and whether the oscillator was stopped in stop mode. refer to modes of operation for more details.
central processor unit (cpu) mc9s08rc/rd/re/rg 82 freescale semiconductor 6.5.5 bgnd instruction the bgnd instruction is new to the hcs08 compared to the m68hc08. bgnd would not be used in normal user programs because it forces the cpu to stop processing user instructions and enter the active background mode. the only way to resume execution of the user program is through reset or by a host debug system issuing a go, trace1, or taggo serial command through the background debug interface. software-based breakpoints can be set by replacing an opcode at the desired breakpoint address with the bgnd opcode. when the program reaches this breakpoint address, the cpu is forced to active background mode rather than continuing the user program. 6.6 hcs08 instruction set summary instruction set summary nomenclature the nomenclature listed here is used in the instruction descriptions in table 6-1 . operators ( ) = contents of register or memory location shown inside parentheses = is loaded with (read: ?ets? & = boolean and | = boolean or = boolean exclusive-or = multiply = divide : = concatenate + = add = negate (twos complement) cpu registers a = accumulator ccr = condition code register h = index register, higher order (most signi?ant) 8 bits x = index register, lower order (least signi?ant) 8 bits pc = program counter pch = program counter, higher order (most signi?ant) 8 bits pcl = program counter, lower order (least signi?ant) 8 bits sp = stack pointer
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 83 mc9s08rc/rd/re/rg memory and addressing m= a memory location or absolute data, depending on addressing mode m:m + $0001= a 16-bit value in two consecutive memory locations. the higher-order (most signi?ant) 8 bits are located at the address of m, and the lower-order (least signi?ant) 8 bits are located at the next higher sequential address. condition code register (ccr) bits v = twos complement over?w indicator, bit 7 h = half carry, bit 4 i = interrupt mask, bit 3 n = negative indicator, bit 2 z = zero indicator, bit 1 c = carry/borrow, bit 0 (carry out of bit 7) ccr activity notation = bit not affected 0 = bit forced to 0 1 = bit forced to 1 = bit set or cleared according to results of operation u = unde?ed after the operation machine coding notation dd = low-order 8 bits of a direct address $0000?00ff (high byte assumed to be $00) ee = upper 8 bits of 16-bit offset ff = lower 8 bits of 16-bit offset or 8-bit offset ii = one byte of immediate data jj = high-order byte of a 16-bit immediate data value kk = low-order byte of a 16-bit immediate data value hh = high-order byte of 16-bit extended address ll = low-order byte of 16-bit extended address rr = relative offset
central processor unit (cpu) mc9s08rc/rd/re/rg 84 freescale semiconductor source form everything in the source forms columns, except expressions in italic characters, is literal information that must appear in the assembly source file exactly as shown. the initial 3- to 5-letter mnemonic is always a literal expression. all commas, pound signs (#), parentheses, and plus signs (+) are literal characters. n any label or expression that evaluates to a single integer in the range 0? opr8i any label or expression that evaluates to an 8-bit immediate value opr16i any label or expression that evaluates to a 16-bit immediate value opr8a any label or expression that evaluates to an 8-bit value. the instruction treats this 8-bit value as the low order 8 bits of an address in the direct page of the 64-kbyte address space ($00xx). opr16a any label or expression that evaluates to a 16-bit value. the instruction treats this value as an address in the 64-kbyte address space. oprx8 any label or expression that evaluates to an unsigned 8-bit value, used for indexed addressing oprx16 any label or expression that evaluates to a 16-bit value. because the hcs08 has a 16-bit address bus, this can be either a signed or an unsigned value. rel any label or expression that refers to an address that is within ?28 to + 127 locations from the next address after the last byte of object code for the current instruction. the assembler will calculate the 8-bit signed offset and include it in the object code for this instruction. address modes inh = inherent (no operands) imm = 8-bit or 16-bit immediate dir = 8-bit direct ext = 16-bit extended ix = 16-bit indexed no offset ix+ = 16-bit indexed no offset, post increment (cbeq and mov only) ix1 = 16-bit indexed with 8-bit offset from h:x ix1+ = 16-bit indexed with 8-bit offset, post increment (cbeq only) ix2 = 16-bit indexed with 16-bit offset from h:x rel = 8-bit relative offset sp1 = stack pointer with 8-bit offset sp2 = stack pointer with 16-bit offset
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 85 mc9s08rc/rd/re/rg table 6-1 hcs08 instruction set summary (sheet 1 of 6) source form operation description effect on ccr address mode opcode operand bus cycles (1) vh i nzc adc # opr8i adc opr8a adc opr16a adc oprx16 ,x adc oprx8 ,x adc ,x adc oprx16 ,sp adc oprx8 ,sp add with carry a (a) + (m) + (c) imm dir ext ix2 ix1 ix sp2 sp1 a9 b9 c9 d9 e9 f9 9ed9 9ee9 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 add # opr8i add opr8a add opr16a add oprx16 ,x add oprx8 ,x add ,x add oprx16 ,sp add oprx8 ,sp add without carry a (a) + (m) imm dir ext ix2 ix1 ix sp2 sp1 ab bb cb db eb fb 9edb 9eeb ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 ais # opr8i add immediate value (signed) to stack pointer sp (sp) + (m) m is sign extended to a 16-bit value imm a7 ii 2 aix # opr8i add immediate value (signed) to index register (h:x) h:x (h:x) + (m) m is sign extended to a 16-bit value imm af ii 2 and # opr8i and opr8a and opr16a and oprx16 ,x and oprx8 ,x and ,x and oprx16 ,sp and oprx8 ,sp logical and a (a) & (m) 0 imm dir ext ix2 ix1 ix sp2 sp1 a4 b4 c4 d4 e4 f4 9ed4 9ee4 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 asl opr8a asla aslx asl oprx8 ,x asl ,x asl oprx8 ,sp arithmetic shift left (same as lsl) dir inh inh ix1 ix sp1 38 48 58 68 78 9e68 dd ff ff 5 1 1 5 4 6 asr opr8a asra asrx asr oprx8 ,x asr ,x asr oprx8 ,sp arithmetic shift right dir inh inh ix1 ix sp1 37 47 57 67 77 9e67 dd ff ff 5 1 1 5 4 6 bcc rel branch if carry bit clear branch if (c) = 0 rel 24 rr 3 bclr n , opr8a clear bit n in memory mn 0 dir (b0) dir (b1) dir (b2) dir (b3) dir (b4) dir (b5) dir (b6) dir (b7) 11 13 15 17 19 1b 1d 1f dd dd dd dd dd dd dd dd 5 5 5 5 5 5 5 5 bcs rel branch if carry bit set (same as blo) branch if (c) = 1 rel 25 rr 3 beq rel branch if equal branch if (z) = 1 rel 27 rr 3 bge rel branch if greater than or equal to (signed operands) branch if (n v ) = 0 rel 90 rr 3 bgnd enter active background if enbdm = 1 waits for and processes bdm commands until go, trace1, or taggo inh 82 5+ bgt rel branch if greater than (signed operands) branch if (z) | (n v ) = 0 rel 92 rr 3 bhcc rel branch if half carry bit clear branch if (h) = 0 rel 28 rr 3 c b0 b7 0 b0 b7 c
central processor unit (cpu) mc9s08rc/rd/re/rg 86 freescale semiconductor bhcs rel branch if half carry bit set branch if (h) = 1 rel 29 rr 3 bhi rel branch if higher branch if (c) | (z) = 0 rel 22 rr 3 bhs rel branch if higher or same (same as bcc) branch if (c) = 0 rel 24 rr 3 bih rel branch if irq pin high branch if irq pin = 1 rel 2f rr 3 bil rel branch if irq pin low branch if irq pin = 0 rel 2e rr 3 bit # opr8i bit opr8a bit opr16a bit oprx16 ,x bit oprx8 ,x bit ,x bit oprx16 ,sp bit oprx8 ,sp bit test (a) & (m) (ccr updated but operands not changed) 0 imm dir ext ix2 ix1 ix sp2 sp1 a5 b5 c5 d5 e5 f5 9ed5 9ee5 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 ble rel branch if less than or equal to (signed operands) branch if (z) | (n v ) = 1 rel 93 rr 3 blo rel branch if lower (same as bcs) branch if (c) = 1 rel 25 rr 3 bls rel branch if lower or same branch if (c) | (z) = 1 rel 23 rr 3 blt rel branch if less than (signed operands) branch if (n v ) = 1 rel 91 rr 3 bmc rel branch if interrupt mask clear branch if (i) = 0 rel 2c rr 3 bmi rel branch if minus branch if (n) = 1 rel 2b rr 3 bms rel branch if interrupt mask set branch if (i) = 1 rel 2d rr 3 bne rel branch if not equal branch if (z) = 0 rel 26 rr 3 bpl rel branch if plus branch if (n) = 0 rel 2a rr 3 bra rel branch always no test rel 20 rr 3 brclr n , opr8a , rel branch if bit n in memory clear branch if (mn) = 0 dir (b0) dir (b1) dir (b2) dir (b3) dir (b4) dir (b5) dir (b6) dir (b7) 01 03 05 07 09 0b 0d 0f dd rr dd rr dd rr dd rr dd rr dd rr dd rr dd rr 5 5 5 5 5 5 5 5 brn rel branch never uses 3 bus cycles rel 21 rr 3 brset n , opr8a , rel branch if bit n in memory set branch if (mn) = 1 dir (b0) dir (b1) dir (b2) dir (b3) dir (b4) dir (b5) dir (b6) dir (b7) 00 02 04 06 08 0a 0c 0e dd rr dd rr dd rr dd rr dd rr dd rr dd rr dd rr 5 5 5 5 5 5 5 5 bset n , opr8a set bit n in memory mn 1 dir (b0) dir (b1) dir (b2) dir (b3) dir (b4) dir (b5) dir (b6) dir (b7) 10 12 14 16 18 1a 1c 1e dd dd dd dd dd dd dd dd 5 5 5 5 5 5 5 5 bsr rel branch to subroutine pc (pc) + $0002 push (pcl); sp (sp) ?$0001 push (pch); sp (sp) ?$0001 pc (pc) + rel rel ad rr 5 table 6-1 hcs08 instruction set summary (sheet 2 of 6) source form operation description effect on ccr address mode opcode operand bus cycles (1) vh i nzc
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 87 mc9s08rc/rd/re/rg cbeq opr8a , rel cbeqa # opr8i , rel cbeqx # opr8i , rel cbeq oprx8 ,x+, rel cbeq ,x+, rel cbeq oprx8 ,sp, rel compare and branch if equal branch if (a) = (m) branch if (a) = (m) branch if (x) = (m) branch if (a) = (m) branch if (a) = (m) branch if (a) = (m) dir imm imm ix1+ ix+ sp1 31 41 51 61 71 9e61 dd rr ii rr ii rr ff rr rr ff rr 5 4 4 5 5 6 clc clear carry bit c 0 0 inh 98 1 cli clear interrupt mask bit i 0 0 inh 9a 1 clr opr8a clra clrx clrh clr oprx8 ,x clr ,x clr oprx8 ,sp clear m $00 a $00 x $00 h $00 m $00 m $00 m $00 001 dir inh inh inh ix1 ix sp1 3f 4f 5f 8c 6f 7f 9e6f dd ff ff 5 1 1 1 5 4 6 cmp # opr8i cmp opr8a cmp opr16a cmp oprx16 ,x cmp oprx8 ,x cmp ,x cmp oprx16 ,sp cmp oprx8 ,sp compare accumulator with memory (a) ?(m) (ccr updated but operands not changed) imm dir ext ix2 ix1 ix sp2 sp1 a1 b1 c1 d1 e1 f1 9ed1 9ee1 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 com opr8a coma comx com oprx8 ,x com ,x com oprx8 ,sp complement (one? complement) m ( m)= $ff ?(m) a ( a) = $ff ?(a) x ( x) = $ff ?(x) m ( m) = $ff ?(m) m ( m) = $ff ?(m) m ( m) = $ff ?(m) 0 1 dir inh inh ix1 ix sp1 33 43 53 63 73 9e63 dd ff ff 5 1 1 5 4 6 cphx opr16a cphx # opr16i cphx opr8a cphx oprx8 ,sp compare index register (h:x) with memory (h:x) ?(m:m + $0001) (ccr updated but operands not changed) ext imm dir sp1 3e 65 75 9ef3 hh ll jj kk dd ff 6 3 5 6 cpx # opr8i cpx opr8a cpx opr16a cpx oprx16 ,x cpx oprx8 ,x cpx ,x cpx oprx16 ,sp cpx oprx8 ,sp compare x (index register low) with memory (x) ?(m) (ccr updated but operands not changed) imm dir ext ix2 ix1 ix sp2 sp1 a3 b3 c3 d3 e3 f3 9ed3 9ee3 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 daa decimal adjust accumulator after add or adc of bcd values (a) 10 u inh 72 1 dbnz opr8a , rel dbnza rel dbnzx rel dbnz oprx8 ,x, rel dbnz ,x, rel dbnz oprx8 ,sp, rel decrement and branch if not zero decrement a, x, or m branch if (result) 0 dbnzx affects x not h dir inh inh ix1 ix sp1 3b 4b 5b 6b 7b 9e6b dd rr rr rr ff rr rr ff rr 7 4 4 7 6 8 dec opr8a deca decx dec oprx8 ,x dec ,x dec oprx8 ,sp decrement m (m) ?$01 a (a) ?$01 x (x) ?$01 m (m) ?$01 m (m) ?$01 m (m) ?$01 dir inh inh ix1 ix sp1 3a 4a 5a 6a 7a 9e6a dd ff ff 5 1 1 5 4 6 div divide a (h:a) (x) h remainder inh 52 6 table 6-1 hcs08 instruction set summary (sheet 3 of 6) source form operation description effect on ccr address mode opcode operand bus cycles (1) vh i nzc
central processor unit (cpu) mc9s08rc/rd/re/rg 88 freescale semiconductor eor # opr8i eor opr8a eor opr16a eor oprx16 ,x eor oprx8 ,x eor ,x eor oprx16 ,sp eor oprx8 ,sp exclusive or memory with accumulator a (a m) 0 imm dir ext ix2 ix1 ix sp2 sp1 a8 b8 c8 d8 e8 f8 9ed8 9ee8 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 inc opr8a inca incx inc oprx8 ,x inc ,x inc oprx8 ,sp increment m (m) + $01 a (a) + $01 x (x) + $01 m (m) + $01 m (m) + $01 m (m) + $01 dir inh inh ix1 ix sp1 3c 4c 5c 6c 7c 9e6c dd ff ff 5 1 1 5 4 6 jmp opr8a jmp opr16a jmp oprx16 ,x jmp oprx8 ,x jmp ,x jump pc jump address dir ext ix2 ix1 ix bc cc dc ec fc dd hh ll ee ff ff 3 4 4 3 3 jsr opr8a jsr opr16a jsr oprx16 ,x jsr oprx8 ,x jsr ,x jump to subroutine pc (pc) + n ( n = 1, 2, or 3) push (pcl); sp (sp) ?$0001 push (pch); sp (sp) ?$0001 pc unconditional address dir ext ix2 ix1 ix bd cd dd ed fd dd hh ll ee ff ff 5 6 6 5 5 lda # opr8i lda opr8a lda opr16a lda oprx16 ,x lda oprx8 ,x lda ,x lda oprx16 ,sp lda oprx8 ,sp load accumulator from memory a (m) 0 imm dir ext ix2 ix1 ix sp2 sp1 a6 b6 c6 d6 e6 f6 9ed6 9ee6 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 ldhx # opr16i ldhx opr8a ldhx opr16a ldhx ,x ldhx oprx16 ,x ldhx oprx8 ,x ldhx oprx8 ,sp load index register (h:x) from memory h:x ( m:m + $0001 ) 0 imm dir ext ix ix2 ix1 sp1 45 55 32 9eae 9ebe 9ece 9efe jj kk dd hh ll ee ff ff ff 3 4 5 5 6 5 5 ldx # opr8i ldx opr8a ldx opr16a ldx oprx16 ,x ldx oprx8 ,x ldx ,x ldx oprx16 ,sp ldx oprx8 ,sp load x (index register low) from memory x (m) 0 imm dir ext ix2 ix1 ix sp2 sp1 ae be ce de ee fe 9ede 9eee ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 lsl opr8a lsla lslx lsl oprx8 ,x lsl ,x lsl oprx8 ,sp logical shift left (same as asl) dir inh inh ix1 ix sp1 38 48 58 68 78 9e68 dd ff ff 5 1 1 5 4 6 lsr opr8a lsra lsr x lsr oprx8 ,x lsr ,x lsr oprx8 ,sp logical shift right 0 dir inh inh ix1 ix sp1 34 44 54 64 74 9e64 dd ff ff 5 1 1 5 4 6 mov opr8a , opr8a mov opr8a ,x+ mov # opr8i , opr8a mov ,x+, opr8a move (m) destination (m) source h:x (h:x) + $0001 in ix+/dir and dir/ix+ modes 0 dir/dir dir/ix+ imm/dir ix+/dir 4e 5e 6e 7e dd dd dd ii dd dd 5 5 4 5 mul unsigned multiply x:a (x) (a) 0 0 inh 42 5 table 6-1 hcs08 instruction set summary (sheet 4 of 6) source form operation description effect on ccr address mode opcode operand bus cycles (1) vh i nzc c b0 b7 0 b0 b7 c 0
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 89 mc9s08rc/rd/re/rg neg opr8a nega negx neg oprx8 ,x neg ,x neg oprx8 ,sp negate (two? complement) m ?(m) = $00 ?(m) a ?(a) = $00 ?(a) x ?(x) = $00 ?(x) m ?(m) = $00 ?(m) m ?(m) = $00 ?(m) m ?(m) = $00 ?(m) dir inh inh ix1 ix sp1 30 40 50 60 70 9e60 dd ff ff 5 1 1 5 4 6 nop no operation uses 1 bus cycle inh 9d 1 nsa nibble swap accumulator a (a[3:0]:a[7:4]) inh 62 1 ora # opr8i ora opr8a ora opr16a ora oprx16 ,x ora oprx8 ,x ora ,x ora oprx16 ,sp ora oprx8 ,sp inclusive or accumulator and memory a (a) | (m) 0 imm dir ext ix2 ix1 ix sp2 sp1 aa ba ca da ea fa 9eda 9eea ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 psha push accumulator onto stack push (a); sp (sp ) $0001 inh 87 2 pshh push h (index register high) onto stack push (h) ; sp (sp ) $0001 inh 8b 2 pshx push x (index register low) onto stack push (x) ; sp (sp ) $0001 inh 89 2 pula pull accumulator from stack sp (sp + $0001); pull ( a ) inh 86 3 pulh pull h (index register high) from stack sp (sp + $0001); pull ( h ) inh 8a 3 pulx pull x (index register low) from stack sp (sp + $0001); pull ( x ) inh 88 3 rol opr8a rola rolx rol oprx8 ,x rol ,x rol oprx8 ,sp rotate left through carry dir inh inh ix1 ix sp1 39 49 59 69 79 9e69 dd ff ff 5 1 1 5 4 6 ror opr8a rora rorx ror oprx8 ,x ror ,x ror oprx8 ,sp rotate right through carry dir inh inh ix1 ix sp1 36 46 56 66 76 9e66 dd ff ff 5 1 1 5 4 6 rsp reset stack pointer sp $ff (high byte not affected) inh 9c 1 rti return from interrupt sp (sp) + $0001; pull (ccr) sp (sp) + $0001; pull (a) sp (sp) + $0001; pull (x) sp (sp) + $0001; pull (pch) sp (sp) + $0001; pull (pcl) inh 80 9 rts return from subroutine sp sp + $0001 ; pull ( pch) sp sp + $0001; pull (pcl) inh 81 6 sbc # opr8i sbc opr8a sbc opr16a sbc oprx16 ,x sbc oprx8 ,x sbc ,x sbc oprx16 ,sp sbc oprx8 ,sp subtract with carry a (a) ?(m) ?(c) imm dir ext ix2 ix1 ix sp2 sp1 a2 b2 c2 d2 e2 f2 9ed2 9ee2 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 sec set carry bit c 1 1 inh 99 1 sei set interrupt mask bit i 1 1 inh 9b 1 table 6-1 hcs08 instruction set summary (sheet 5 of 6) source form operation description effect on ccr address mode opcode operand bus cycles (1) vh i nzc c b0 b7 b0 b7 c
central processor unit (cpu) mc9s08rc/rd/re/rg 90 freescale semiconductor sta opr8a sta opr16a sta oprx16 ,x sta oprx8 ,x sta ,x sta oprx16 ,sp sta oprx8 ,sp store accumulator in memory m (a) 0 dir ext ix2 ix1 ix sp2 sp1 b7 c7 d7 e7 f7 9ed7 9ee7 dd hh ll ee ff ff ee ff ff 3 4 4 3 2 5 4 sthx opr8a sthx opr16a sthx oprx8 ,sp store h:x (index reg.) (m:m + $0001) (h:x) 0 dir ext sp1 35 96 9eff dd hh ll ff 4 5 5 stop enable interrupts: stop processing refer to mcu documentation i bit 0; stop processing 0 inh 8e 2+ stx opr8a stx opr16a stx oprx16 ,x stx oprx8 ,x stx ,x stx oprx16 ,sp stx oprx8 ,sp store x (low 8 bits of index register) in memory m (x) 0 dir ext ix2 ix1 ix sp2 sp1 bf cf df ef ff 9edf 9eef dd hh ll ee ff ff ee ff ff 3 4 4 3 2 5 4 sub # opr8i sub opr8a sub opr16a sub oprx16 ,x sub oprx8 ,x sub ,x sub oprx16 ,sp sub oprx8 ,sp subtract a (a) (m) imm dir ext ix2 ix1 ix sp2 sp1 a0 b0 c0 d0 e0 f0 9ed0 9ee0 ii dd hh ll ee ff ff ee ff ff 2 3 4 4 3 3 5 4 swi software interrupt pc (pc) + $0001 push (pcl); sp (sp) ?$0001 push (pch); sp (sp) ?$0001 push (x); sp (sp) ?$0001 push (a); sp (sp) ?$0001 push (ccr); sp (sp) ?$0001 i 1; pch interrupt vector high byte pcl interrupt vector low byte 1 inh 83 11 tap transfer accumulator to ccr ccr (a) inh 84 1 tax transfer accumulator to x (index register low) x (a) inh 97 1 tpa transfer ccr to accumulator a (ccr) inh 85 1 tst opr8a tsta tstx tst oprx8 ,x tst ,x tst oprx8 ,sp test for negative or zero (m) ?$00 (a) ?$00 (x) ?$00 (m) ?$00 (m) ?$00 (m) ?$00 0 dir inh inh ix1 ix sp1 3d 4d 5d 6d 7d 9e6d dd ff ff 4 1 1 4 3 5 tsx transfer sp to index reg. h:x (sp) + $0001 inh 95 2 txa transfer x (index reg. low) to accumulator a (x) inh 9f 1 txs transfer index reg. to sp sp (h:x) ?$0001 inh 94 2 wait enable interrupts; wait for interrupt i bit 0; halt cpu 0 inh 8f 2+ notes : 1. bus clock frequency is one-half of the cpu clock frequency. table 6-1 hcs08 instruction set summary (sheet 6 of 6) source form operation description effect on ccr address mode opcode operand bus cycles (1) vh i nzc
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 91 mc9s08rc/rd/re/rg table 6-2 opcode map (sheet 1 of 2) bit-manipulation branch read-modify-write control register/memory 00 5 brset0 3 dir 10 5 bset0 2 dir 20 3 bra 2 rel 30 5 neg 2 dir 40 1 nega 1 inh 50 1 negx 1 inh 60 5 neg 2 ix1 70 4 neg 1ix 80 9 rti 1 inh 90 3 bge 2 rel a0 2 sub 2 imm b0 3 sub 2 dir c0 4 sub 3 ext d0 4 sub 3 ix2 e0 3 sub 2 ix1 f0 3 sub 1ix 01 5 brclr0 3 dir 11 5 bclr0 2 dir 21 3 brn 2 rel 31 5 cbeq 3 dir 41 4 cbeqa 3 imm 51 4 cbeqx 3 imm 61 5 cbeq 3 ix1+ 71 5 cbeq 2 ix+ 81 6 rts 1 inh 91 3 blt 2 rel a1 2 cmp 2 imm b1 3 cmp 2 dir c1 4 cmp 3 ext d1 4 cmp 3 ix2 e1 3 cmp 2 ix1 f1 3 cmp 1ix 02 5 brset1 3 dir 12 5 bset1 2 dir 22 3 bhi 2 rel 32 5 ldhx 3 ext 42 5 mul 1 inh 52 6 div 1 inh 62 1 nsa 1 inh 72 1 daa 1 inh 82 5+ bgnd 1 inh 92 3 bgt 2 rel a2 2 sbc 2 imm b2 3 sbc 2 dir c2 4 sbc 3 ext d2 4 sbc 3 ix2 e2 3 sbc 2 ix1 f2 3 sbc 1ix 03 5 brclr1 3 dir 13 5 bclr1 2 dir 23 3 bls 2 rel 33 5 com 2 dir 43 1 coma 1 inh 53 1 comx 1 inh 63 5 com 2 ix1 73 4 com 1ix 83 11 swi 1 inh 93 3 ble 2 rel a3 2 cpx 2 imm b3 3 cpx 2 dir c3 4 cpx 3 ext d3 4 cpx 3 ix2 e3 3 cpx 2 ix1 f3 3 cpx 1ix 04 5 brset2 3 dir 14 5 bset2 2 dir 24 3 bcc 2 rel 34 5 lsr 2 dir 44 1 lsra 1 inh 54 1 lsrx 1 inh 64 5 lsr 2 ix1 74 4 lsr 1ix 84 1 ta p 1 inh 94 2 txs 1 inh a4 2 and 2 imm b4 3 and 2 dir c4 4 and 3 ext d4 4 and 3 ix2 e4 3 and 2 ix1 f4 3 and 1ix 05 5 brclr2 3 dir 15 5 bclr2 2 dir 25 3 bcs 2 rel 35 4 sthx 2 dir 45 3 ldhx 3 imm 55 4 ldhx 2 dir 65 3 cphx 3 imm 75 5 cphx 2 dir 85 1 tpa 1 inh 95 2 tsx 1 inh a5 2 bit 2 imm b5 3 bit 2 dir c5 4 bit 3 ext d5 4 bit 3 ix2 e5 3 bit 2 ix1 f5 3 bit 1ix 06 5 brset3 3 dir 16 5 bset3 2 dir 26 3 bne 2 rel 36 5 ror 2 dir 46 1 rora 1 inh 56 1 rorx 1 inh 66 5 ror 2 ix1 76 4 ror 1ix 86 3 pula 1 inh 96 5 sthx 3 ext a6 2 lda 2 imm b6 3 lda 2 dir c6 4 lda 3 ext d6 4 lda 3 ix2 e6 3 lda 2 ix1 f6 3 lda 1ix 07 5 brclr3 3 dir 17 5 bclr3 2 dir 27 3 beq 2 rel 37 5 asr 2 dir 47 1 asra 1 inh 57 1 asrx 1 inh 67 5 asr 2 ix1 77 4 asr 1ix 87 2 psha 1 inh 97 1 ta x 1 inh a7 2 ais 2 imm b7 3 sta 2 dir c7 4 sta 3 ext d7 4 sta 3 ix2 e7 3 sta 2 ix1 f7 2 sta 1ix 08 5 brset4 3 dir 18 5 bset4 2 dir 28 3 bhcc 2 rel 38 5 lsl 2 dir 48 1 lsla 1 inh 58 1 lslx 1 inh 68 5 lsl 2 ix1 78 4 lsl 1ix 88 3 pulx 1 inh 98 1 clc 1 inh a8 2 eor 2 imm b8 3 eor 2 dir c8 4 eor 3 ext d8 4 eor 3 ix2 e8 3 eor 2 ix1 f8 3 eor 1ix 09 5 brclr4 3 dir 19 5 bclr4 2 dir 29 3 bhcs 2 rel 39 5 rol 2 dir 49 1 rola 1 inh 59 1 rolx 1 inh 69 5 rol 2 ix1 79 4 rol 1ix 89 2 pshx 1 inh 99 1 sec 1 inh a9 2 adc 2 imm b9 3 adc 2 dir c9 4 adc 3 ext d9 4 adc 3 ix2 e9 3 adc 2 ix1 f9 3 adc 1ix 0a 5 brset5 3 dir 1a 5 bset5 2 dir 2a 3 bpl 2 rel 3a 5 dec 2 dir 4a 1 deca 1 inh 5a 1 decx 1 inh 6a 5 dec 2 ix1 7a 4 dec 1ix 8a 3 pulh 1 inh 9a 1 cli 1 inh aa 2 ora 2 imm ba 3 ora 2 dir ca 4 ora 3 ext da 4 ora 3 ix2 ea 3 ora 2 ix1 fa 3 ora 1ix 0b 5 brclr5 3 dir 1b 5 bclr5 2 dir 2b 3 bmi 2 rel 3b 7 dbnz 3 dir 4b 4 dbnza 2 inh 5b 4 dbnzx 2 inh 6b 7 dbnz 3 ix1 7b 6 dbnz 2ix 8b 2 pshh 1 inh 9b 1 sei 1 inh ab 2 add 2 imm bb 3 add 2 dir cb 4 add 3 ext db 4 add 3 ix2 eb 3 add 2 ix1 fb 3 add 1ix 0c 5 brset6 3 dir 1c 5 bset6 2 dir 2c 3 bmc 2 rel 3c 5 inc 2 dir 4c 1 inca 1 inh 5c 1 incx 1 inh 6c 5 inc 2 ix1 7c 4 inc 1ix 8c 1 clrh 1 inh 9c 1 rsp 1 inh bc 3 jmp 2 dir cc 4 jmp 3 ext dc 4 jmp 3 ix2 ec 3 jmp 2 ix1 fc 3 jmp 1ix 0d 5 brclr6 3 dir 1d 5 bclr6 2 dir 2d 3 bms 2 rel 3d 4 tst 2 dir 4d 1 tsta 1 inh 5d 1 tstx 1 inh 6d 4 tst 2 ix1 7d 3 tst 1ix 9d 1 nop 1 inh ad 5 bsr 2 rel bd 5 jsr 2 dir cd 6 jsr 3 ext dd 6 jsr 3 ix2 ed 5 jsr 2 ix1 fd 5 jsr 1ix 0e 5 brset7 3 dir 1e 5 bset7 2 dir 2e 3 bil 2 rel 3e 6 cphx 3 ext 4e 5 mov 3dd 5e 5 mov 2 dix+ 6e 4 mov 3 imd 7e 5 mov 2 ix+d 8e 2+ stop 1 inh 9e page 2 ae 2 ldx 2 imm be 3 ldx 2 dir ce 4 ldx 3 ext de 4 ldx 3 ix2 ee 3 ldx 2 ix1 fe 3 ldx 1ix 0f 5 brclr7 3 dir 1f 5 bclr7 2 dir 2f 3 bih 2 rel 3f 5 clr 2 dir 4f 1 clra 1 inh 5f 1 clrx 1 inh 6f 5 clr 2 ix1 7f 4 clr 1ix 8f 2+ wait 1 inh 9f 1 txa 1 inh af 2 aix 2 imm bf 3 stx 2 dir cf 4 stx 3 ext df 4 stx 3 ix2 ef 3 stx 2 ix1 ff 2 stx 1ix inh inherent rel relative sp1 stack pointer, 8-bit offset imm immediate ix indexed, no offset sp2 stack pointer, 16-bit offset dir direct ix1 indexed, 8-bit offset ix+ indexed, no offset with ext extended ix2 indexed, 16-bit offset post increment dd dir to dir imd imm to dir ix1+ indexed, 1-byte offset with ix+d ix+ to dir dix+ dir to ix+ post increment opcode in hexadecimal number of bytes f0 3 sub 1ix hcs08 cycles instruction mnemonic addressing mode
central processor unit (cpu) mc9s08rc/rd/re/rg 92 freescale semiconductor bit-manipulation branch read-modify-write control register/memory 9e60 6 neg 3 sp1 9ed0 5 sub 4 sp2 9ee0 4 sub 3 sp1 9e61 6 cbeq 4 sp1 9ed1 5 cmp 4 sp2 9ee1 4 cmp 3 sp1 9ed2 5 sbc 4 sp2 9ee2 4 sbc 3 sp1 9e63 6 com 3 sp1 9ed3 5 cpx 4 sp2 9ee3 4 cpx 3 sp1 9ef3 6 cphx 3 sp1 9e64 6 lsr 3 sp1 9ed4 5 and 4 sp2 9ee4 4 and 3 sp1 9ed5 5 bit 4 sp2 9ee5 4 bit 3 sp1 9e66 6 ror 3 sp1 9ed6 5 lda 4 sp2 9ee6 4 lda 3 sp1 9e67 6 asr 3 sp1 9ed7 5 sta 4 sp2 9ee7 4 sta 3 sp1 9e68 6 lsl 3 sp1 9ed8 5 eor 4 sp2 9ee8 4 eor 3 sp1 9e69 6 rol 3 sp1 9ed9 5 adc 4 sp2 9ee9 4 adc 3 sp1 9e6a 6 dec 3 sp1 9eda 5 ora 4 sp2 9eea 4 ora 3 sp1 9e6b 8 dbnz 4 sp1 9edb 5 add 4 sp2 9eeb 4 add 3 sp1 9e6c 6 inc 3 sp1 9e6d 5 tst 3 sp1 9eae 5 ldhx 2ix 9ebe 6 ldhx 4 ix2 9ece 5 ldhx 3 ix1 9ede 5 ldx 4 sp2 9eee 4 ldx 3 sp1 9efe 5 ldhx 3 sp1 9e6f 6 clr 3 sp1 9edf 5 stx 4 sp2 9eef 4 stx 3 sp1 9eff 5 sthx 3 sp1 inh inherent rel relative sp1 stack pointer, 8-bit offset imm immediate ix indexed, no offset sp2 stack pointer, 16-bit offset dir direct ix1 indexed, 8-bit offset ix+ indexed, no offset with ext extended ix2 indexed, 16-bit offset post increment dd dir to dir imd imm to dir ix1+ indexed, 1-byte offset with ix+d ix+ to dir dix+ dir to ix+ post increment note: all sheet 2 opcodes are preceded by the page 2 prebyte (9e) prebyte (9e) and opcode in hexadecimal number of bytes 9e60 6 neg 3 sp1 hcs08 cycles instruction mnemonic addressing mode table 6-2 opcode map (sheet 2 of 2)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 93 mc9s08rc/rd/re/rg chapter 7 carrier modulator timer (cmt) module 7.1 introduction figure 7-1 mc9s08rc/rd/re/rg block diagram ptd3 ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 ptc1/kbi2p1 ptc0/kbi2p0 v ss v dd ptb3 ptb2 pta7/kbi1p7 ptb0/txd1 ptb1/rxd1 ptd2/irq ptd1/ reset ptd0/bkgd/ms ptc7/ ss1 ptc6/spsck1 ptc5/miso1 ptc4/mosi1 ptc3/kbi2p3 ptc2/kbi2p2 port a port c port d port b 8-bit keyboard interrupt module (kbi1) serial peripheral interface module (spi1) user flash user ram (rc/rd/re/rg32/60 = 2048 bytes) debug module (dbg) (rc/rd/re/rg60 = 63,364 bytes) hcs08 core bdc cpu notes: 1. port pins are software configurable with pullup device if input port 2. pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . 3. irq pin contains software configurable pullup/pulldown device if irq enabled (irqpe = 1) 4. the reset pin contains integrated pullup device enabled if reset enabled (rstpe = 1) 5. high current drive. 6. pins pta[7:0] contain both pullup and pulldown devices. pulldown available when kbi enabled (kbi1pn = 1). notes notes 1, 5 2-channel timer/pwm module (tpm1) pte7 port e ptb5 ptb4 pte6 ptb7/tpm1ch1 module (acmp1) hcs08 system control resets and interrupts modes of operation power management voltage regulator rti analog comparator cop irq lvd internal bus low-power oscillator interface module (sci1) serial communications 7 pta1/kbi1p1 8 pte0 note 1 notes1, 2, 6 note 1 (rc/rd/re/rg32 = 32,768 bytes) (rc/rd/re8/16 = 1024 bytes) (rc/rd/re16 = 16,384 bytes) xtal extal carrier modulator timer module (cmt) 1, 3, 4 4-bit keyboard interrupt module (kbi2) iro note 5 pta0/kbi1p0 (rc/rd/re8 = 8192 bytes)
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 94 freescale semiconductor 7.2 features the cmt consists of a carrier generator, modulator, and transmitter that drives the infrared out (iro) pin. the features of this module include: four modes of operation time with independent control of high and low times baseband frequency shift key (fsk) direct software control of iro pin extended space operation in time, baseband, and fsk modes selectable input clock divide: 1, 2, 4, or 8 interrupt on end of cycle ability to disable iro pin and use as timer interrupt 7.3 cmt block diagram figure 7-2 carrier modulator transmitter module block diagram carrier generator modulator carrier out (f cg ) modulator out transmitter output base fsk primary/secondary select cmt registers iro pin eoc flag eoc int en mireq and bus interface bus clock cmtclk cmtdiv clock control mcgen exspc cmtpol cmtcg regs cmtcmd regs irol internal bus iireq iropen
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 95 mc9s08rc/rd/re/rg 7.4 pin description the iro pin is the only pin associated with the cmt. the pin is driven by the transmitter output when the mcgen bit in the cmtmsc register and the iropen bit in the cmtoc register are set. if the mcgen bit is clear and the iropen bit is set, the pin is driven by the irol bit in the cmtoc register. this enables user software to directly control the state of the iro pin by writing to the irol bit. if the iropen bit is clear, the pin is disabled and is not driven by the cmt module. this is so the cmt can be configured as a modulo timer for generating periodic interrupts without causing pin activity. 7.5 functional description the cmt module consists of a carrier generator, a modulator, a transmitter output, and control registers. the block diagram is shown in figure 7-2 . when operating in time mode, the user independently defines the high and low times of the carrier signal to determine both period and duty cycle. the carrier generator resolution is 125 ns when operating with an 8 mhz internal bus frequency and the cmtdiv1 and cmtdiv0 bits in the cmtmsc register are both equal to 0. the carrier generator can generate signals with periods between 250 ns (4 mhz) and 127.5 s (7.84 khz) in steps of 125 ns. see table 7-1 . the possible duty cycle options will depend upon the number of counts required to complete the carrier period. for example, a 1.6 mhz signal has a period of 625 ns and will therefore require 5 125 ns counts to generate. these counts may be split between high and low times, so the duty cycles available will be 20 percent (one high, four low), 40 percent (two high, three low), 60 percent (three high, two low) and 80 percent (four high, one low). for lower frequency signals with larger periods, higher resolution (as a percentage of the total period) duty cycles are possible. when the base bit in the cmt modulator status and control register (cmtmsc) is set, the carrier output (f cg ) to the modulator is held high continuously to allow for the generation of baseband protocols. a third mode allows the carrier generator to alternate between two sets of high and low times. when operating in fsk mode, the generator will toggle between the two sets when instructed by the modulator, allowing the user to dynamically switch between two carrier frequencies without cpu intervention. table 7-1 clock divide bus clock (mhz) cmtdiv1:cmtdiv0 carrier generator resolution ( s) min carrier generator period ( s) min modulator period ( s) 8 0:0 0.125 0.25 1.0 8 0:1 0.25 0.5 2.0 8 1:0 0.5 1.0 4.0 8 1:1 1.0 2.0 8.0
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 96 freescale semiconductor the modulator provides a simple method to control protocol timing. the modulator has a minimum resolution of 1.0 s with an 8 mhz internal bus clock. it can count bus clocks (to provide real-time control) or it can count carrier clocks (for self-clocked protocols). see 7.5.2 modulator for more details. the transmitter output block controls the state of the infrared out pin (iro). the modulator output is gated on to the iro pin when the modulator/carrier generator is enabled. a summary of the possible modes is shown in table 7-2 . 7.5.1 carrier generator the carrier signal is generated by counting a register-selected number of input clocks (125 ns for an 8 mhz bus) for both the carrier high time and the carrier low time. the period is determined by the total number of clocks counted. the duty cycle is determined by the ratio of high time clocks to total clocks counted. the high and low time values are user programmable and are held in two registers. an alternate set of high/low count values is held in another set of registers to allow the generation of dual frequency fsk (frequency shift keying) protocols without cpu intervention. note: only non-zero data values are allowed. the carrier generator will not work if any of the count values are equal to zero. the mcgen bit in the cmtmsc register must be set and the base bit must be cleared to enable carrier generator clocks. when the base bit is set, the carrier output to the modulator is held high continuously. the block diagram is shown in figure 7-3 . table 7-2 cmt modes of operation mode mcgen bit (1) notes : 1. to prevent spurious operation, initialize all data and control registers before beginning a transmission (mcgen=1). base bit (2) 2. these bits are not double buffered and should not be changed during a transmission (while mcgen=1). fsk bit (2) exspc bit comment time 1 0 0 0 f cg controlled by primary high and low registers. f cg transmitted to iro pin when modulator gate is open. baseband 1 1 x 0 f cg is always high. iro pin high when modulator gate is open. fsk 1 0 1 0 f cg control alternates between primary high/low registers and secondary high/low registers. f cg transmitted to iro pin when modulator gate is open. extended space 1xx1 setting the exspc bit causes subsequent modulator cycles to be spaces (modulator out not asserted) for the duration of the modulator period (mark and space times). iro latch 0 x x x irol bit controls state of iro pin.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 97 mc9s08rc/rd/re/rg figure 7-3 carrier generator block diagram the high/low time counter is an 8-bit up counter. after each increment, the contents of the counter are compared with the appropriate high or low count value register. when the compare value is reached, the counter is reset to a value of $01, and the compare is redirected to the other count value register. assuming that the high time count compare register is currently active, a valid compare will cause the carrier output to be driven low. the counter will continue to increment (starting at reset value of $01). when the value stored in the selected low count value register is reached, the counter will again be reset and the carrier output will be driven high. the cycle repeats, automatically generating a periodic signal that is directed to the modulator. the lowest frequency (maximum period) and highest frequency (minimum period) that can be generated are defined as: f max = f cmtclk (2 x 1) hz f min = f cmtclk (2 x (2 8 ?1)) hz in the general case, the carrier generator output frequency is: f cg = f cmtclk (highcount + lowcount) hz where: 0 < highcount < 256 and 0 < lowcount < 256 clk 8-bit up counter =? =? clr clock and output control cmtcgh1 cmtcgh2 primary/ select carrier out (f cg ) secondary cmtcgl2 cmtcgl1 cmtclk base fsk mcgen
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 98 freescale semiconductor the duty cycle of the carrier signal is controlled by varying the ratio of high time to low + high time. as the input clock period is fixed, the duty cycle resolution will be proportional to the number of counts required to generate the desired carrier period. 7.5.2 modulator the modulator has three main modes of operation: gate the carrier onto the modulator output (time mode) control the logic level of the modulator output (baseband mode) count carrier periods and instruct the carrier generator to alternate between two carrier frequencies whenever a modulation period (mark + space counts) expires (fsk mode) the modulator includes a 17-bit down counter with underflow detection. the counter is loaded from the 16-bit modulation mark period buffer registers, cmtcmd1 and cmtcmd2. the most significant bit is loaded with a logic zero and serves as a sign bit. when the counter holds a positive value, the modulator gate is open and the carrier signal is driven to the transmitter block. when the counter underflows, the modulator gate is closed and a 16-bit comparator is enabled that compares the logical complement of the value of the down-counter with the contents of the modulation space period register (which has been loaded from the registers cmtcmd3 and cmtcmd4). when a match is obtained the cycle repeats by opening the modulator gate, reloading the counter with the contents of cmtcmd1 and cmtcmd2, and reloading the modulation space period register with the contents of cmtcmd3 and cmtcmd4. if the contents of the modulation space period register are all zeroes, the match will be immediate and no space period will be generated (for instance, for fsk protocols that require successive bursts of different frequencies). the mcgen bit in the cmtmsc register must be set to enable the modulator timer. duty cycle highcount highcount lowcount + ---------------------------------------------------------------- =
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 99 mc9s08rc/rd/re/rg figure 7-4 modulator block diagram 7.5.2.1 time mode when the modulator operates in time mode (mcgen bit is set, base bit is clear, and fsk bit is clear), the modulation mark period consists of an integer number of cmtclk 8 clock periods. the modulation space period consists of zero or an integer number of cmtclk 8 clock periods. with an 8 mhz bus and cmtdiv1:cmtdiv0 = 00, the modulator resolution is 1 s and has a maximum mark and space period of about 65.535 ms each. see figure 7-5 for an example of the time mode and baseband mode outputs. the mark and space time equations for time and baseband mode are: t mark = (cmtcmd1:cmtcmd2 + 1) ( f cmtclk 8) t space = cmtcmd3:cmtcmd4 ( f cmtclk 8) where cmtcmd1:cmtcmd2 and cmtcmd3:cmtcmd4 are the decimal values of the concatenated registers. =? 0 counter cmtclock cmtcmd1:cmtcmd2 cmtcmd3:cmtcmd4 space period register * 17-bit down counter * * denotes hidden register 16 bits 16 bits ms bit 16 16 module interrupt request 8 clock control carrier out (f cg ) load system control eoc flag set modulator gate out primary/secondary select . . modulator exspc mode eocie base fsk
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 100 freescale semiconductor figure 7-5 example cmt output in time and baseband modes 7.5.2.2 baseband mode baseband mode (mcgen bit is set and base bit is set) is a derivative of time mode, where the mark and space period is based on (cmtclk 8) counts. the mark and space calculations are the same as in time mode. in this mode the modulator output will be at a logic 1 for the duration of the mark period and at a logic 0 for the duration of a space period. see figure 7-5 for an example of the output for both baseband and time modes. in the example, the carrier out frequency (f cg ) is generated with a high count of $01 and a low count of $02, which results in a divide of 3 of cmtclk with a 33 percent duty cycle. the modulator down-counter was loaded with the value $0003 and the space period register with $0002. note: the waveforms in figure 7-5 and figure 7-6 are for the purpose of conceptual illustration and are not meant to represent precise timing relationships between the signals shown. 7.5.2.3 fsk mode when the modulator operates in fsk mode (mcgen bit is set, fsk bit is set, and base bit is clear), the modulation mark and space periods consist of an integer number of carrier clocks (space period can be 0). when the mark period expires, the space period is transparently started (as in time mode). the carrier generator toggles between primary and secondary data register values whenever the modulator space period expires. modulator gate cmtclk 8 iro pin (time mode) iro pin mark space mark carrier out (f cg ) (baseband mode)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 101 mc9s08rc/rd/re/rg the space period provides an interpulse gap (no carrier). if cmtcmd3:cmtcmd4 = $0000, then the modulator and carrier generator will switch between carrier frequencies without a gap or any carrier glitches (zero space). using timing data for carrier burst and interpulse gap length calculated by the cpu, fsk mode can automatically generate a phase-coherent, dual-frequency fsk signal with programmable burst and interburst gaps. the mark and space time equations for fsk mode are: t mark = (cmtcmd1:cmtcmd2 + 1) f cg t space = cmtcmd3:cmtcmd4 f cg where f cg is the frequency output from the carrier generator. the example in figure 7-6 shows what the iro pin output looks like in fsk mode with the following values: cmtcmd1:cmtcmd2 = $0003, cmtcmd3:cmtcmd4 = $0002, primary carrier high count = $01, primary carrier low count = $02, secondary carrier high count = $03, and secondary carrier low count = $01. figure 7-6 example cmt output in fsk mode 7.5.3 extended space operation in time, baseband, or fsk mode, the space period can be made longer than the maximum possible value of the space period register. setting the exspc bit in the cmtmsc register will force the modulator to treat the next modulation period (beginning with the next load of the counter and space period register) as a space period equal in length to the mark and space counts combined. subsequent modulation periods will consist entirely of these extended space periods with no mark periods. clearing exspc will return the modulator to standard operation at the beginning of the next modulation period. mark1 space1 mark2 space2 mark1 space1 mark2 modulator gate carrier out (f cg ) iro pin
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 102 freescale semiconductor 7.5.3.1 exspc operation in time mode to calculate the length of an extended space in time or baseband modes, add the mark and space times and multiply by the number of modulation periods that exspc is set. t exspace = t space + (t mark + t space ) x (number of modulation periods) for an example of extended space operation, see figure 7-7 . note: the exspc feature can be used to emulate a zero mark event. figure 7-7 extended space operation 7.5.3.2 exspc operation in fsk mode in fsk mode, the modulator continues to count carrier out clocks, alternating between the primary and secondary registers at the end of each modulation period. to calculate the length of an extended space in fsk mode, the user must know whether the exspc bit was set on a primary or secondary modulation period, as well as the total number of both primary and secondary modulation periods completed while the exspc bit is high. a status bit for the current modulation is not accessible to the cpu. if necessary, software should maintain tracking of the current modulation cycle (primary or secondary). the extended space period ends at the completion of the space period time of the modulation period during which the exspc bit is cleared. if the exspc bit was set during a primary modulation cycle, use the equation: t exspace = (t space ) p + (t mark + t space ) s + (t mark + t space ) p +... where the subscripts p and s refer to mark and space times for the primary and secondary modulation cycles. if the exspc bit was set during a secondary modulation cycle, use the equation: t exspace = (t space ) s + (t mark + t space ) p + (t mark + t space ) s +... 7.5.4 transmitter the transmitter output block controls the state of the infrared out pin (iro). the modulator output is gated on to the iro pin when the modulator/carrier generator is enabled. when the modulator/carrier generator is disabled, the iro pin is controlled by the state of the iro latch. a polarity bit in the cmtoc register enables the iro pin to be high true or low true. set exspc clear exspc
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 103 mc9s08rc/rd/re/rg 7.5.5 cmt interrupts the end of cycle flag (eocf) is set when: the modulator is not currently active and the mcgen bit is set to begin the initial cmt transmission at the end of each modulation cycle (when the counter is reloaded from cmtcmd1:cmtcmd2) while the mcgen bit is set in the case where the mcgen bit is cleared and then set before the end of the modulation cycle, the eocf bit will not be set when the mcgen is set, but will become set at the end of the current modulation cycle. when the mcgen becomes disabled, the cmt module does not set the eoc flag at the end of the last modulation cycle. the eocf bit is cleared by reading the cmt modulator status and control register (cmtmsc) followed by an access of cmtcmd2 or cmtcmd4. if the eoc interrupt enable (eocie) bit is high when the eocf bit is set, the cmt module will generate an interrupt request. the eocf bit must be cleared within the interrupt service routine to prevent another interrupt from being generated after exiting the interrupt service routine. the eoc interrupt is coincident with loading the down-counter with the contents of cmtcmd1:cmtcmd2 and loading the space period register with the contents of cmtcmd3:cmtcmd4. the eoc interrupt provides a means for the user to reload new mark/space values into the modulator data registers. modulator data register updates will take effect at the end of the current modulation cycle. note that the down-counter and space period register are updated at the end of every modulation cycle, regardless of interrupt handling and the state of the eocf flag. 7.5.6 wait mode operation during wait mode the cmt, if enabled, will continue to operate normally. however, there will be no new codes or changes of pattern mode while in wait mode, because the cpu is not operating. 7.5.7 stop mode operation during all stop modes, clocks to the cmt module are halted. in stop1 and stop2 modes, all cmt register data is lost and must be re-initialized upon recovery from these two stop modes. no cmt module registers are affected in stop3 mode. note, because the clocks are halted, the cmt will resume upon exit from stop (only in stop3 mode). software should ensure stop2 or stop3 mode is not entered while the modulator is in operation to prevent the iro pin from being asserted while in stop mode. this may require a time-out period from the time that the mcgen bit is cleared to allow the last modulator cycle to complete.
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 104 freescale semiconductor 7.5.8 background mode operation when the microcontroller is in active background mode, the cmt temporarily suspends all counting until the microcontroller returns to normal user mode. 7.6 cmt registers and control bits the following registers control and monitor cmt operation: cmt carrier generator data registers (cmtcgh1, cmtcgl1, cmtcgh2, cmtcgl2) cmt output control register (cmtoc) cmt modulator status and control register (cmtmsc) cmt modulator period data registers (cmtcmd1, cmtcmd2, cmtcmd3, cmtcmd4) 7.6.1 carrier generator data registers (cmtcgh1, cmtcgl1, cmtcgh2, and cmtcgl2) the carrier generator data registers contain the primary and secondary high and low values for generating the carrier output.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 105 mc9s08rc/rd/re/rg cmtcgh1 bit 7 6 5 4321 bit 0 read: ph7 ph6 ph5 ph4 ph3 ph2 ph1 ph0 write: reset: u u u uuuuu cmtcgl1 bit 7 6 5 4321 bit 0 read: pl7 pl6 pl5 pl4 pl3 pl2 pl1 pl0 write: reset: u u u uuuuu cmtcgh2 bit 7 6 5 4321 bit 0 read: sh7 sh6 sh5 sh4 sh3 sh2 sh1 sh0 write: reset: u u u uuuuu cmtcgl2 bit 7 6 5 4321 bit 0 read: sl7 sl6 sl5 sl4 sl3 sl2 sl1 sl0 write: reset: u u u uuuuu u = unaffected figure 7-8 cmt carrier generator data registers (cmtcgh1, cmtcgl1, cmtcgh2, cmtcgl2)
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 106 freescale semiconductor ph0?h7 and pl0?l7 primary carrier high and low time data values when selected, these bits contain the number of input clocks required to generate the carrier high and low time periods. when operating in time mode (see 7.5.2.1 time mode ), this register pair is always selected. when operating in fsk mode (see 7.5.2.3 fsk mode ), this register pair and the secondary register pair are alternatively selected under control of the modulator. the primary carrier high and low time values are undefined out of reset. these bits must be written to nonzero values before the carrier generator is enabled to avoid spurious results. sh0?h7 and sl0?l7 secondary carrier high and low time data values when selected, these bits contain the number of input clocks required to generate the carrier high and low time periods. when operating in time mode (see 7.5.2.1 time mode ), this register pair is never selected. when operating in fsk mode (see 7.5.2.3 fsk mode ), this register pair and the primary register pair are alternatively selected under control of the modulator. the secondary carrier high and low time values are undefined out of reset. these bits must be written to nonzero values before the carrier generator is enabled when operating in fsk mode. 7.6.2 cmt output control register (cmtoc) this register is used to control the iro output of the cmt module. irol iro latch control reading irol reads the state of the iro latch. writing irol changes the state of the iro pin when the mcgen bit is clear in the cmtmsc register and the iropen bit is set. cmtpol cmt output polarity the cmtpol bit controls the polarity of the iro pin output of the cmt. 1 = iro pin is active high 0 = iro pin is active low bit 7 654321 bit 0 read: irol cmtpol iropen 00000 write: reset: 00000000 = unimplemented figure 7-9 cmt output control register (cmtoc)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 107 mc9s08rc/rd/re/rg iropen iro pin enable the iropen bit is used to enable and disable the iro pin. when the pin is enabled, it is an output that drives out either the cmt transmitter output or the state of the irol bit depending on whether the mcgen bit in the cmtmsc register is set. also, the state of the output is either inverted or not depending on the state of the cmtpol bit. when the pin is disabled, it is in a high impedance state so it doesn? draw any current. the pin is disabled during reset. 1 = iro pin enabled as output 0 = iro pin disabled 7.6.3 cmt modulator status and control register (cmtmsc) the cmt modulator status and control register (cmtmsc) contains the modulator and carrier generator enable (mcgen), end of cycle interrupt enable (eocie), fsk mode select (fsk), baseband enable (base), extended space (exspc), prescaler (cmtdiv1:cmtdiv0) bits, and the end of cycle (eocf) status bit. eocf end of cycle status flag the eocf bit is set when: the modulator is not currently active and the mcgen bit is set to begin the initial cmt transmission. at the end of each modulation cycle while the mcgen bit is set. this is recognized when a match occurs between the contents of the space period register and the down-counter. at this time, the counter is initialized with the (possibly new) contents of the mark period buffer, cmtcmd1 and cmtcmd2. the space period register is loaded with the (possibly new) contents of the space period buffer, cmtcmd3 and cmtcmd4. this flag is cleared by a read of the cmtmsc register followed by an access of cmtcmd2 or cmtcmd4. in the case where the mcgen bit is cleared and then set before the end of the modulation cycle, eocf will not be set when mcgen is set, but will be set at the end of the current modulation cycle. 1 = end of modulator cycle has occurred 0 = no end of modulation cycle occurrence since flag last cleared bit 7 654321 bit 0 read: eocf cmtdiv1 cmtdiv0 exspc base fsk eocie mcgen write: reset: 00000000 = unimplemented figure 7-10 cmt modulator status and control register (cmtmsc)
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 108 freescale semiconductor cmtdiv1:cmtdiv0 cmt clock divide prescaler the cmt clock divide prescaler causes the cmt to be clocked at the bus clock frequency, or the bus clock frequency divided by 1, 2, 4, or 8. because these bits are not double buffered, they should not be changed during a transmission. exspc extended space enable the exspc bit enables extended space operation. 1 = extended space enabled 0 = extended space disabled base baseband enable when set, the base bit disables the carrier generator and forces the carrier output high for generation of baseband protocols. when base is clear, the carrier generator is enabled and the carrier output toggles at the frequency determined by values stored in the carrier data registers. see 7.5.2.2 baseband mode . this bit is cleared by reset. this bit is not double buffered and should not be written to during a transmission. 1 = baseband mode enabled 0 = baseband mode disabled fsk fsk mode select the fsk bit enables fsk operation. 1 = cmt operates in fsk mode 0 = cmt operates in time or baseband mode eocie end of cycle interrupt enable a cpu interrupt will be requested when eocf is set if eocie is high. 1 = cpu interrupt enabled 0 = cpu interrupt disabled table 7-3 cmt clock divide prescaler cmtdiv1:cmtdiv0 cmt clock divide 00 bus clock 1 01 bus clock 2 10 bus clock 4 11 bus clock 8
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 109 mc9s08rc/rd/re/rg mcgen modulator and carrier generator enable setting mcgen will initialize the carrier generator and modulator and enable all clocks. after it is enabled, the carrier generator and modulator will function continuously. when mcgen is cleared, the current modulator cycle will be allowed to expire before all carrier and modulator clocks are disabled (to save power) and the modulator output is forced low. to prevent spurious operation, the user should initialize all data and control registers before enabling the system. 1 = modulator and carrier generator enabled 0 = modulator and carrier generator disabled 7.6.4 cmt modulator data registers (cmtcmd1, cmtcmd2, cmtcmd3, and cmtcmd4) the modulator data registers control the mark and space periods of the modulator for all modes. the contents of these registers are transferred to the modulator down counter and space period register upon the completion of a modulation period. figure 7-11 cmt modulator data registers (cmtcmd1, cmtcmd2, cmtcmd3, and cmtcmd4) cmtcmd1 bit 7 654321 bit 0 read: mb15 mb14 mb13 mb12 mb11 mb10 mb9 mb8 write: reset: unaffected by reset cmtcmd2 bit 7 654321 bit 0 read: mb7 mb6 mb5 mb4 mb3 mb2 mb1 mb0 write: reset: unaffected by reset cmtcmd3 bit 7 654321 bit 0 read: sb15 sb14 sb13 sb12 sb11 sb10 sb9 sb8 write: reset: unaffected by reset cmtcmd4 bit 7 654321 bit 0 read: sb7 sb6 sb5 sb4 sb3 sb2 sb1 sb0 write: reset: unaffected by reset
carrier modulator transmitter (cmt) module mc9s08rc/rd/re/rg 110 freescale semiconductor
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 111 mc9s08rc/rd/re/rg chapter 8 parallel input/output 8.1 introduction this section explains software controls related to parallel input/output (i/o). the mc9s08rc/rd/re/rg has five i/o ports that include a total of 39 general-purpose i/o pins (two of these pins are output only and one pin is input only). not all of the ports are available in all packages. see chapter 2 pins and connections for more information about the logic and hardware aspects of these pins. many of these pins are shared with on-chip peripherals such as timer systems, external interrupts, or keyboard interrupts. when these other modules are not controlling the port pins, they revert to general-purpose i/o control. for each i/o pin, a port data bit provides access to input (read) and output (write) data. a data direction bit controls the direction of the pin and a pullup enable bit enables an internal pullup device (if the pin is configured as an input). note: not all general-purpose i/o pins are available on all packages. to avoid extra current drain from floating input pins, the user? reset initialization routine in the application program should either enable on-chip pullup devices or change the direction of unconnected pins to outputs so the pins do not float. 8.2 features parallel i/o features for the mc9s08rc/rd/re/rg mcus, depending on specific device and package choice, include: a total of 39 general-purpose i/o pins in five ports (two pins are output only, one is input only) high-current drivers on port b pins hysteresis input buffers on all inputs software-controlled pullups on each input pin eight port a pins shared with kbi1 eight port b pins shared with sci and tpmch1 eight port c pins shared with kbi2 and spi seven port d pins shared with tpmch0, acmp, irq, reset, and bkgd/ms eight port e pins 8.3 pin descriptions the mc9s08rc/rd/re/rg has a total of 39 parallel i/o pins distributed between four 8-bit ports and one 7-bit port. not all pins are bonded out in all packages. consult the pin assignment in the pins and connections section for available parallel i/o pins. all of these pins are available for general-purpose i/o when they are not used by other on-chip peripheral systems.
parallel input/output mc9s08rc/rd/re/rg 112 freescale semiconductor the following paragraphs discuss each port and the software controls that determine each pin? use. 8.3.1 port a figure 8-1 port a pin names port a is an 8-bit general-purpose i/o port shared with the kbi1 keyboard interrupt inputs. bit 0 of port a is an input-only pin. port a pins are available as general-purpose i/o pins controlled by the port a data (ptad), data direction (ptadd), and pullup enable (ptape) registers. refer to 8.4 parallel i/o controls for more information about general-purpose i/o control. any of the port a pins can be configured as a kbi1 keyboard interrupt pin. refer to the keyboard interrupt (kbi) module section for more information about using port a pins as keyboard interrupt pins. 8.3.2 port b figure 8-2 port b pin names port b is an 8-bit general-purpose i/o port with two pins shared with the sci and one pin shared with the tpm. the port b output drivers are capable of high current drive. port b pins are available as general-purpose i/o pins controlled by the port b data (ptbd), data direction (ptbdd), and pullup enable (ptbpe) registers. refer to 8.4 parallel i/o controls for more information about general-purpose i/o control. when the sci module is enabled, ptb0 and ptb1 function as the transmit (txd1) and receive (rxd1) pins of the sci. refer to the serial communications interface (sci) module section for more information about using ptb0 and ptb1 as sci pins. the tpm can be configured to use ptb7 as either an input capture, output compare, or pwm pin. refer to the timer/pwm module (tpm) module section for more information about using ptb7 as a timer pin. port a bit 7 654321 bit 0 mcu pin: pta7/ kbi1p7 pta6/ kbi1p6 pta5/ kbi1p5 pta4/ kbi1p4 pta3/ kbi1p3 pta2/ kbi1p2 pta1/ kbi1p1 pta0/ kbi1p0 port b bit 7 654321 bit 0 mcu pin: ptb7/ tpm1ch1 ptb6 ptb5 ptb4 ptb3 ptb2 ptb1/ rxd1 ptb0/ txd1
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 113 mc9s08rc/rd/re/rg 8.3.3 port c figure 8-3 port c pin names port c is an 8-bit general-purpose i/o port with four pins shared with the kbi2 keyboard interrupt inputs and four pins shared with the spi. port c pins are available as general-purpose i/o pins controlled by the port c data (ptcd), data direction (ptcdd), and pullup enable (ptcpe) registers. refer to 8.4 parallel i/o controls for more information about general-purpose i/o control. when the spi module is enabled, ptc7 serves as the spi module? slave select pin ( ss1), ptc6 serves as the spi clock pin (spsck1), ptc5 serves as the master-in slave-out pin (miso1), and ptc4 serves as the master-out slave-in pin (mosi1). refer to the serial peripheral interface (spi) module section for more information about using ptc7?tc4 as spi pins. any of the port c pins ptc3-ptc0 can be configured as a kbi2 keyboard interrupt pin. refer to the keyboard interrupt (kbi) module section for more information about using port c pins as keyboard interrupt pins. 8.3.4 port d figure 8-4 port d pin names port d is an 7-bit general-purpose i/o port with one pin shared with the bkgd/ms function, one pin shared with the reset function, one pin shared with the irq function, and one pin shared with the tpm. port d pins are available as general-purpose i/o pins controlled by the port d data (ptdd), data direction (ptddd), and pullup enable (ptdpe) registers. refer to 8.4 parallel i/o controls for more information about general-purpose i/o control. the ptd0/bkgd/ms pin is configured for the bkgd/ms function during reset and following reset. the internal pullup for this pin is enabled when the bkgd/ms function is enabled, regardless of the ptdpe0 bit. during reset, the bkgd/ms pin functions as a mode select pin. after the mcu is out of reset, the bkgd/ms pin becomes the background communications input/output pin. ptd0 can be configured to be a general-purpose output pin through software control. refer to the modes of operation section, the resets, interrupts, and system configuration section, and the development support section for more information about using this pin. port c bit 7 653321 bit 0 mcu pin: ptc7/ ss1 ptc6/ spsck1 ptc5/ miso1 ptc4/ mosi1 ptc3/ kbi2p3 ptc2/ kbi2p2 ptc1/ kbi2p1 ptc0/ kbi2p0 port d bit 7 6 54321 bit 0 mcu pin: ptd6/ tpm1ch0 ptd5 ptd4 ptd3 ptd2 ptd1/ reset ptd0/ bkgd/ms
parallel input/output mc9s08rc/rd/re/rg 114 freescale semiconductor the ptd1/ reset pin is configured for the reset function during reset and following reset. the tpm can be configured to use ptd6 as either an input capture, output compare, pwm, or external clock input pin. refer to the parallel input/output section for more information about using ptd6 as a timer pin. 8.3.5 port e figure 8-5 port e pin names port e is an 8-bit general-purpose i/o port. port e pins are available as general-purpose i/o pins controlled by the port e data (pted), data direction (ptedd), and pullup enable (ptepe) registers. refer to 8.4 parallel i/o controls for more information about general-purpose i/o control. 8.4 parallel i/o controls provided no on-chip peripheral is controlling a port pin, the pins operate as general-purpose i/o pins that are accessed and controlled by a data register (ptxd), a data direction register (ptxdd), and a pullup enable register (ptxpe) where x is a, b, c, d, or e. reads of the data register return the pin value (if ptxddn = 0) or the contents of the port data register (if ptxddn = 1). writes to the port data register are latched into the port register whether the pin is controlled by an on-chip peripheral or the pin is configured as an input. if the corresponding pin is not controlled by a peripheral and is configured as an output, this level will be driven out the port pin. 8.4.1 data direction control the data direction control bits determine whether the pin output driver is enabled, and they control what is read for port data register reads. each port pin has a data direction control bit. when ptxddn = 0, the corresponding pin is an input and reads of ptxd return the pin value. when ptxddn = 1, the corresponding pin is an output and reads of ptxd return the last value written to the port data register. when a peripheral module or system function is in control of a port pin, the data direction control still controls what is returned for reads of the port data register, even though the peripheral system has overriding control of the actual pin direction. for the mc9s08rc/rd/re/rg mcu, reads of ptd0/bkgd/ms and ptd1/ reset will return the value on the output pin. it is a good programming practice to write to the port data register before changing the direction of a port pin to become an output. this ensures that the pin will not be driven with an old data value that happened to be in the port data register. port e bit 7 654321 bit 0 mcu pin: pte7 pte6 pte5 pte4 pte3 pte2 pte1 pte0
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 115 mc9s08rc/rd/re/rg 8.4.2 internal pullup control an internal pullup device can be enabled for each port pin that is configured as an input (ptxddn = 0). the pullup device is available for a peripheral module to use, provided the peripheral is enabled and is an input function as long as the ptxddn = 0. note: the voltage measured on the pulled up pta0 pin will be less than v dd . the internal gates connected to this pin are pulled all the way to v dd . all other pins with enabled pullup resistors will have an unloaded measurement of v dd . 8.5 stop modes depending on the stop mode, i/o functions differently as the result of executing a stop instruction. an explanation of i/o behavior for the various stop modes follows: when the mcu enters stop1 mode, all internal registers, including general-purpose i/o control and data registers, are powered down. all of the general-purpose i/o pins assume their reset state: output buffers and pullups turned off. upon exit from stop1, all i/o must be initialized as if the mcu had been reset. when the mcu enters stop2 mode, the internal registers are powered down as in stop1 but the i/o pin states are latched and held. for example, a port pin that is an output driving low continues to function as an output driving low even though its associated data direction and output data registers are powered down internally. upon exit from stop2, the pins continue to hold their states until a 1 is written to the ppdack bit. to avoid discontinuity in the pin state following exit from stop2, the user must restore the port control and data registers to the values they held befor4e entering stop2. these values can be stored in ram before entering stop2 because the ram is maintained during stop2. in stop3 mode, all i/o is maintained because internal logic circuity stays powered up. upon recovery, normal i/o function is available to the user. 8.6 parallel i/o registers and control bits this section provides information about all registers and control bits associated with the parallel i/o ports. refer to tables in the memory section for the absolute address assignments for all parallel i/o registers. this section refers to registers and control bits only by their names. a freescale-provided equate or header file normally is used to translate these names into the appropriate absolute addresses. 8.6.1 port a registers (ptad, ptape, and ptadd) port a pins used as general-purpose i/o pins are controlled by the port a data (ptad), data direction (ptadd), and pullup enable (ptape) registers.
parallel input/output mc9s08rc/rd/re/rg 116 freescale semiconductor figure 8-6 port a registers ptadn port a data register bit n (n = 0?) for port a pins that are inputs, reads of this register return the logic level on the pin. for port a pins that are configured as outputs, reads of this register return the last value written to this register. writes are latched into all bits of this register. for port a pins that are configured as outputs, the logic level is driven out the corresponding mcu pin. reset forces ptad to all 0s, but these 0s are not driven out the corresponding pins because reset also configures all port pins as high-impedance inputs with pullups disabled. ptapen pullup enable for port a bit n (n = 0?) for port a pins that are inputs, these read/write control bits determine whether internal pullup devices are enabled provided the corresponding ptaddn is a logic 0. for port a pins that are configured as outputs, these bits are ignored and the internal pullup devices are disabled. when any of bits 7 through 4 of port a are enabled as kbi inputs and are configured to detect rising edges/high levels, the pullup enable bits enable pulldown rather than pullup devices. 1 = internal pullup device enabled. 0 = internal pullup device disabled. ptaddn data direction for port a bit n (n = 0?) these read/write bits control the direction of port a pins and what is read for ptad reads. 1 = output driver enabled for port a bit n and ptad reads return the contents of ptadn. 0 = input (output driver disabled) and reads return the pin value. ptad bit 7 654321 bit 0 read: ptad7 ptad6 ptad5 ptad4 ptad3 ptad2 ptad1 ptad0 write: reset: 00000000 ptape read: ptape7 ptape6 ptape5 ptape4 ptape3 ptape2 ptape1 ptape0 write: reset: 00000000 ptadd read: ptadd7 ptadd6 ptadd5 ptadd4 ptadd3 ptadd2 ptadd1 ptadd0 write: reset: 00000000
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 117 mc9s08rc/rd/re/rg 8.6.2 port b registers (ptbd, ptbpe, and ptbdd) port b pins used as general-purpose i/o pins are controlled by the port b data (ptbd), data direction (ptbdd), and pullup enable (ptbpe) registers. figure 8-7 port b registers ptbdn port b data register bit n (n = 0?) for port b pins that are inputs, reads return the logic level on the pin. for port b pins that are configured as outputs, reads return the last value written to this register. writes are latched into all bits of this register. for port b pins that are configured as outputs, the logic level is driven out the corresponding mcu pin. reset forces ptbd to all 0s, but these 0s are not driven out on the corresponding pins because reset also configures all port pins as high-impedance inputs with pullups disabled. ptbpen pullup enable for port b bit n (n = 0?) for port b pins that are inputs, these read/write control bits determine whether internal pullup devices are enabled. for port b pins that are configured as outputs, these bits are ignored and the internal pullup devices are disabled. 1 = internal pullup device enabled. 0 = internal pullup device disabled. ptbddn data direction for port b bit n (n = 0?) these read/write bits control the direction of port b pins and what is read for ptbd reads. 1 = output driver enabled for port b bit n and ptbd reads return the contents of ptbdn. 0 = input (output driver disabled) and reads return the pin value. ptbd bit 7 654321 bit 0 read: ptbd7 ptbd6 ptbd5 ptbd4 ptbd3 ptbd2 ptbd1 ptbd0 write: reset: 00000000 ptbpe read: ptbpe7 ptbpe6 ptbpe5 ptbpe4 ptbpe3 ptbpe2 ptbpe1 ptbpe0 write: reset: 00000000 ptbdd read: ptbdd7 ptbdd6 ptbdd5 ptbdd4 ptbdd3 ptbdd2 ptbdd1 ptbdd0 write: reset: 00000000
parallel input/output mc9s08rc/rd/re/rg 118 freescale semiconductor 8.6.3 port c registers (ptcd, ptcpe, and ptcdd) port c pins used as general-purpose i/o pins are controlled by the port c data (ptcd), data direction (ptcdd), and pullup enable (ptcpe) registers. figure 8-8 port c registers ptcdn port c data register bit n (n = 0?) for port c pins that are inputs, reads return the logic level on the pin. for port c pins that are configured as outputs, reads return the last value written to this register. writes are latched into all bits of this register. for port c pins that are configured as outputs, the logic level is driven out the corresponding mcu pin. reset forces ptcd to all 0s, but these 0s are not driven out the corresponding pins because reset also configures all port pins as high-impedance inputs with pullups disabled. ptcpen pullup enable for port c bit n (n = 0?) for port c pins that are inputs, these read/write control bits determine whether internal pullup devices are enabled. for port c pins that are configured as outputs, these bits are ignored and the internal pullup devices are disabled. 1 = internal pullup device enabled. 0 = internal pullup device disabled. ptcddn data direction for port c bit n (n = 0?) these read/write bits control the direction of port c pins and what is read for ptcd reads. 1 = output driver enabled for port c bit n and ptcd reads return the contents of ptcdn. 0 = input (output driver disabled) and reads return the pin value. ptcd bit 7 654321 bit 0 read: ptcd7 ptcd6 ptcd5 ptcd4 ptcd3 ptcd2 ptcd1 ptcd0 write: reset: 00000000 ptcpe read: ptcpe7 ptcpe6 ptcpe5 ptcpe4 ptcpe3 ptcpe2 ptcpe1 ptcpe0 write: reset: 00000000 ptcdd read: ptcdd7 ptcdd6 ptcdd5 ptcdd4 ptcdd3 ptcdd2 ptcdd1 ptcdd0 write: reset: 00000000
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 119 mc9s08rc/rd/re/rg 8.6.4 port d registers (ptdd, ptdpe, and ptddd) port d pins used as general-purpose i/o pins are controlled by the port d data (ptdd), data direction (ptddd), and pullup enable (ptdpe) registers. figure 8-9 port d registers ptddn port d data register bit n (n = 0?) for port d pins that are inputs, reads return the logic level on the pin. for port d pins that are configured as outputs, reads return the last value written to this register. writes are latched into all bits of this register. for port d pins that are configured as outputs, the logic level is driven out the corresponding mcu pin. reset forces ptdd to all 0s, but these 0s are not driven out the corresponding pins because reset also configures all port pins as high-impedance inputs with pullups disabled. ptdpen pullup enable for port d bit n (n = 0?) for port d pins that are inputs, these read/write control bits determine whether internal pullup devices are enabled. for port d pins that are configured as outputs, these bits are ignored and the internal pullup devices are disabled. 1 = internal pullup device enabled. 0 = internal pullup device disabled. ptdddn data direction for port d bit n (n = 0?) these read/write bits control the direction of port d pins and what is read for ptdd reads. 1 = output driver enabled for port d bit n and ptdd reads return the contents of ptddn. 0 = input (output driver disabled) and reads return the pin value. ptdd bit 7 654321 bit 0 read: 0 ptdd6 ptdd5 ptdd4 ptdd3 ptdd2 ptdd1 ptdd0 write: reset: 00000000 ptdpe read: 0 ptdpe6 ptdpe5 ptdpe4 ptdpe3 ptdpe2 ptdpe1 ptdpe0 write: reset: 00000000 ptddd read: 0 ptddd6 ptddd5 ptddd4 ptddd3 ptddd2 ptddd1 ptddd0 write: reset: 00000000 = unimplemented or reserved
parallel input/output mc9s08rc/rd/re/rg 120 freescale semiconductor 8.6.5 port e registers (pted, ptepe, and ptedd) port e pins used as general-purpose i/o pins are controlled by the port e data (pted), data direction (ptedd), and pullup enable (ptepe) registers. figure 8-10 port e registers ptedn port e data register bit n (n = 0?) for port e pins that are inputs, reads return the logic level on the pin. for port e pins that are configured as outputs, reads return the last value written to this register. writes are latched into all bits of this register. for port e pins that are configured as outputs, the logic level is driven out the corresponding mcu pin. reset forces pted to all 0s, but these 0s are not driven out the corresponding pins because reset also configures all port pins as high-impedance inputs with pullups disabled. ptepen pullup enable for port e bit n (n = 0?) for port e pins that are inputs, these read/write control bits determine whether internal pullup devices are enabled. for port e pins that are configured as outputs, these bits are ignored and the internal pullup devices are disabled. 1 = internal pullup device enabled. 0 = internal pullup device disabled. pteddn data direction for port e bit n (n = 0?) these read/write bits control the direction of port e pins and what is read for pted reads. 1 = output driver enabled for port e bit n and pted reads return the contents of ptedn. 0 = input (output driver disabled) and reads return the pin value. pted bit 7 654321 bit 0 read: pted7 pted6 pted5 pted4 pted3 pted2 pted1 pted0 write: reset: 00000000 ptepe read: ptepe7 ptepe6 ptepe5 ptepe4 ptepe3 ptepe2 ptepe1 ptepe0 write: reset: 00000000 ptedd read: ptedd7 ptedd6 ptedd5 ptedd4 ptedd3 ptedd2 ptedd1 ptedd0 write: reset: 00000000
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 121 mc9s08rc/rd/re/rg chapter 9 keyboard interrupt (kbi) module 9.1 introduction the mc9s08rc/rd/re/rg has two kbi modules. one has eight keyboard interrupt inputs that share port a pins. the other kbi module has four inputs that are shared on the upper four pins of port c. see the pins and connections section for more information about the logic and hardware aspects of these pins. port a is an 8-bit port that is shared between the kbi1 keyboard interrupt inputs and general-purpose i/o. the eight kbi1pen control bits in the kbi1pe register allow selection of any combination of port a pins to be assigned as kbi1 inputs. any pins that are enabled as kbi1 inputs will be forced to act as inputs and the remaining port a pins are available as general-purpose i/o pins controlled by the port a data (ptad), data direction (ptadd) and pullup enable (ptape) registers. the eight ptapen control bits in the ptape register allow the user to select whether an internal pullup device is enabled on each port a pin that is configured as a port input or a kbi1 input. kbi1 inputs can be configured for edge-only sensitivity or edge-and-level sensitivity. bits 3 through 0 of port a are falling-edge/low-level sensitive and bits 7 through 4 can be configured for rising-edge/high-level or for falling-edge/low-level sensitivity. port c is an 8-bit port with its lower four pins shared between the kbi2 keyboard interrupt inputs and general-purpose i/o. the four kbi2pen control bits in the kbi2pe register allow selection of any combination of the lower four port c pins to be assigned as kbi2 inputs. any pins that are enabled as kbi2 inputs will be forced to act as inputs and the remaining port c pins are available as general-purpose i/o pins controlled by the port c data (ptcd), data direction (ptcdd) and pullup enable (ptcpe) registers. the eight ptcpen control bits in the ptcpe register allow the user to select whether an internal pullup device is enabled on each port c pin that is configured as a port input or a kbi2 input. any enabled keyboard interrupt can be used to wake the mcu from wait, standby (stop3), partial power-down (stop2) or power-down modes (stop1). in either stop1 or stop2 mode, an input functions as a falling edge/low-level wakeup, therefore it should be configured to use falling-edge sensing if the mcu will be used in stop1 or stop2 modes.
keyboard interrupt (kbi) module mc9s08rc/rd/re/rg 122 freescale semiconductor figure 9-1 mc9s08rc/rd/re/rg block diagram ptd3 ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 ptc1/kbi2p1 ptc0/kbi2p0 v ss v dd ptb3 ptb2 pta7/kbi1p7 ptb0/txd1 ptb1/rxd1 ptd2/irq ptd1/ reset ptd0/bkgd/ms ptc7/ ss1 ptc6/spsck1 ptc5/miso1 ptc4/mosi1 ptc3/kbi2p3 ptc2/kbi2p2 port a port c port d port b 8-bit keyboard interrupt module (kbi1) serial peripheral interface module (spi1) user flash user ram (rc/rd/re/rg32/60 = 2048 bytes) debug module (dbg) (rc/rd/re/rg60 = 63,364 bytes) hcs08 core notes: 1. port pins are software configurable with pullup device if input port 2. pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . 3. irq pin contains software configurable pullup/pulldown device if irq enabled (irqpe = 1) 4. the reset pin contains integrated pullup device enabled if reset enabled (rstpe = 1) 5. high current drive 6. pins pta[7:0] contain both pullup and pulldown devices. pulldown available when kbi enabled (kbi1pn = 1). notes notes 1, 5 2-channel timer/pwm module (tpm1) pte7 port e ptb5 ptb4 pte6 ptb7/tpm1ch1 module (acmp1) hcs08 system control resets and interrupts modes of operation power management voltage regulator rti analog comparator cop irq lvd internal bus low-power oscillator interface module (sci1) serial communications 7 pta1/kbi1p1 8 pte0 note 1 notes1, 2 note 1 (rc/rd/re/rg32 = 32,768 bytes) (rc/rd/re8/16 = 1024 bytes) (rc/rd/re16 = 16,384 bytes) xtal extal carrier modulator timer module (cmt) 1, 3, 4 4-bit keyboard interrupt module (kbi2) iro note 5 pta0/kbi1p0 (rc/rd/re8 = 8192 bytes) bdc cpu
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 123 mc9s08rc/rd/re/rg 9.2 kbi block diagram figure 9-2 shows the block diagram for a kbi module. figure 9-2 kbi block diagram the kbi module allows up to eight pins to act as additional interrupt sources. four of these pins allow falling-edge sensing while the other four can be configured for either rising-edge sensing or falling-edge sensing. the sensing mode for all eight pins can also be modified to detect edges and levels instead of only edges. 9.3 keyboard interrupt (kbi) module this on-chip peripheral module is called a keyboard interrupt (kbi) module because originally it was designed to simplify the connection and use of row-column matrices of keyboard switches. however, these inputs are also useful as extra external interrupt inputs and as an external means of waking up the mcu from stop or wait low-power modes. 9.3.1 pin enables the kbipen control bits in the kbixpe register allow a user to enable (kbipen = 1) any combination of kbi-related port pins to be connected to the kbi module. pins corresponding to 0s in kbixpe are general-purpose i/o pins that are not associated with the kbi module. 9.3.2 edge and level sensitivity synchronous logic is used to detect edges. prior to detecting an edge, enabled keyboard inputs in a kbi module must be at the deasserted logic level. keyboard interrupt dq ck clr v dd kbimod kbie keyboard interrupt ff request kback reset synchronizer kbf stop bypass stop busclk kbipen 0 1 s kbedgn kbipe0 kbipe3 kbipe4 0 1 s kbedg4 kbixp0 kbixp3 kbixp4 kbixpn
keyboard interrupt (kbi) module mc9s08rc/rd/re/rg 124 freescale semiconductor a falling edge is detected when an enabled keyboard input signal is seen as a logic 1 (the deasserted level) during one bus cycle and then a logic 0 (the asserted level) during the next cycle. a rising edge is detected when the input signal is seen as a logic 0 during one bus cycle and then a logic 1 during the next cycle. the kbimod control bit can be set to reconfigure the detection logic so that it detects edges and levels. in kbimod = 1 mode, the kbf status flag becomes set when an edge is detected (when one or more enabled pins change from the deasserted to the asserted level while all other enabled pins remain at their deasserted levels), but the flag is continuously set (and cannot be cleared) as long as any enabled keyboard input pin remains at the asserted level. when the mcu enters stop mode, the synchronous edge-detection logic is bypassed (because clocks are stopped). in stop mode, kbi inputs act as asynchronous level-sensitive inputs so they can wake the mcu from stop mode. 9.3.3 kbi interrupt controls the kbf status flag becomes set (1) when an edge event has been detected on any kbi input pin. if kbie = 1 in the kbixsc register, a hardware interrupt will be requested whenever kbf = 1. the kbf flag is cleared by writing a 1 to the keyboard acknowledge (kback) bit. when kbimod = 0 (selecting edge-only operation), kbf is always cleared by writing 1 to kback. when kbimod = 1 (selecting edge-and-level operation), kbf cannot be cleared as long as any keyboard input is at its asserted level. 9.4 kbi registers and control bits this section provides information about all registers and control bits associated with the kbi modules. refer to the direct-page register summary in the memory section of this data sheet for the absolute address assignments for all kbi registers. this section refers to registers and control bits only by their names. a freescale-provided equate or header file is used to translate these names into the appropriate absolute addresses. some mcu systems have more than one kbi, so register names include placeholder characters to identify which kbi is being referenced. for example, kbixsc refers to the kbix status and control register and kbi2sc is the status and control register for kbi2. 9.4.1 kbi x status and control register (kbixsc) figure 9-3 kbi x status and control register (kbixsc) bit 7 654321 bit 0 read: kbedg7 kbedg6 kbedg5 kbedg4 kbf 0 kbie kbimod write: kback reset: 00000000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 125 mc9s08rc/rd/re/rg kbedgn keyboard edge select for kbi port bit n (n = 7?) each of these read/write bits selects the polarity of the edges and/or levels that are recognized as trigger events on the corresponding kbi port pin when it is configured as a keyboard interrupt input (kbipen = 1). also see the kbimod control bit, which determines whether the pin is sensitive to edges-only or edges and levels. 1 = rising edges/high levels. 0 = falling edges/low levels. kbf keyboard interrupt flag this read-only status flag is set whenever the selected edge event has been detected on any of the enabled kbi port pins. this flag is cleared by writing a logic 1 to the kback control bit. the flag will remain set if kbimod = 1 to select edge-and-level operation and any enabled kbi port pin remains at the asserted level. 1 = kbi interrupt pending. 0 = no kbi interrupt pending. kbf can be used as a software pollable flag (kbie = 0) or it can generate a hardware interrupt request to the cpu (kbie = 1). kback keyboard interrupt acknowledge this write-only bit (reads always return 0) is used to clear the kbf status flag by writing a logic 1 to kback. when kbimod = 1 to select edge-and-level operation and any enabled kbi port pin remains at the asserted level, kbf is being continuously set so writing 1 to kback does not clear the kbf flag. kbie keyboard interrupt enable this read/write control bit determines whether hardware interrupts are generated when the kbf status flag equals 1. when kbie = 0, no hardware interrupts are generated, but kbf can still be used for software polling. 1 = kbi hardware interrupt requested when kbf = 1. 0 = kbf does not generate hardware interrupts (use polling). kbimod keyboard detection mode this read/write control bit selects either edge-only detection or edge-and-level detection. kbi port bits 3 through 0 can detect falling edges-only or falling edges and low levels. kbi port bits 7 through 4 can be configured to detect either: rising edges-only or rising edges and high levels (kbedgn = 1) falling edges-only or falling edges and low levels (kbedgn = 0) 1 = edge-and-level detection. 0 = edge-only detection.
keyboard interrupt (kbi) module mc9s08rc/rd/re/rg 126 freescale semiconductor 9.4.2 kbi x pin enable register (kbixpe) figure 9-4 kbi x pin enable register (kbixpe) kbipen keyboard pin enable for kbi port bit n (n = 7?) each of these read/write bits selects whether the associated kbi port pin is enabled as a keyboard interrupt input or functions as a general-purpose i/o pin. 1 = bit n of kbi port enabled as a keyboard interrupt input 0 = bit n of kbi port is a general-purpose i/o pin not associated with the kbi. bit 7 654321 bit 0 read: kbipe7 kbipe6 kbipe5 kbipe4 kbipe3 kbipe2 kbipe1 kbipe0 write: reset: 00000000
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 127 mc9s08rc/rd/re/rg chapter 10 timer/pwm module (tpm) module 10.1 introduction the mc9s08rc/rd/re/rg includes a timer/pwm (tpm) module that supports traditional input capture, output compare, or buffered edge-aligned pulse-width modulation (pwm) on each channel. a control bit in the tpm configures both channels in the timer to operate as center-aligned pwm functions. timing functions in the tpm are based on a 16-bit counter with prescaler and modulo features to control frequency and range (period between overflows) of the time reference. this timing system is ideally suited for a wide range of control applications. the mc9s08rc/rd/re/rg devices do not have a separate fixed internal clock source (xclk). if the xclk source is selected using the clksa and clksb control bits (see table 10-1 ), the tpm will use the busclk. 10.2 features timer system features include: two separate channels: each channel may be input capture, output compare, or buffered edge-aligned pwm rising-edge, falling-edge, or any-edge input capture trigger set, clear, or toggle output compare action selectable polarity on pwm outputs the tpm may be configured for buffered, center-aligned pulse-width modulation (cpwm) on both channels clock source to prescaler for the tpm is selectable between the bus clock or an external pin: prescale taps for divide by 1, 2, 4, 8, 16, 32, 64, or 128 external clock input shared with tpm1ch0 timer channel pin 16-bit modulus register to control counter range timer system enable one interrupt per channel plus terminal count interrupt
timer/pwm module (tpm) module mc9s08rc/rd/re/rg 128 freescale semiconductor figure 10-1 mc9s08rc/rd/re/rg block diagram highlighting tpm block and pins ptd3 ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 ptc1/kbi2p1 ptc0/kbi2p0 v ss v dd ptb3 ptb2 pta7/kbi1p7 ptb0/txd1 ptb1/rxd1 ptd2/irq ptd1/ reset ptd0/bkgd/ms ptc7/ ss1 ptc6/spsck1 ptc5/miso1 ptc4/mosi1 ptc3/kbi2p3 ptc2/kbi2p2 port a port c port d port b 8-bit keyboard interrupt module (kbi1) serial peripheral interface module (spi1) user flash user ram (rc/rd/re/rg32/60 = 2048 bytes) debug module (dbg) (rc/rd/re/rg60 = 63,364 bytes) hcs08 core notes: 1. port pins are software configurable with pullup device if input port 2. pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . 3. irq pin contains software configurable pullup/pulldown device if irq enabled (irqpe = 1) 4. the reset pin contains integrated pullup device enabled if reset enabled (rstpe = 1) 5. high current drive 6. pins pta[7:0] contain both pullup and pulldown devices. pulldown available when kbi enabled (kbi1pn = 1). notes notes 1, 5 2-channel timer/pwm module (tpm1) pte7 port e ptb5 ptb4 pte6 ptb7/tpm1ch1 module (acmp1) hcs08 system control resets and interrupts modes of operation power management voltage regulator rti analog comparator cop irq lvd internal bus low-power oscillator interface module (sci1) serial communications 7 pta1/kbi1p1 8 pte0 note 1 notes1, 2 note 1 (rc/rd/re/rg32 = 32,768 bytes) (rc/rd/re8/16 = 1024 bytes) (rc/rd/re16 = 16,384 bytes) xtal extal carrier modulator timer module (cmt) 1, 3, 4 4-bit keyboard interrupt module (kbi2) iro note 5 pta0/kbi1p0 (rc/rd/re8 = 8192 bytes) bdc cpu
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 129 mc9s08rc/rd/re/rg 10.3 tpm block diagram the tpm uses one input/output (i/o) pin per channel, tpm1chn where x is the tpm number (for example, 1 or 2) and n is the channel number (for example, 0?). the tpm shares its i/o pins with general-purpose i/o port pins (refer to the pins and connections section for more information). figure 10-2 shows the structure of a tpm. some mcus include more than one tpm, with various numbers of channels. figure 10-2 tpm block diagram prescale and select 16-bit comparator main 16-bit counter 16-bit comparator 16-bit latch port 16-bit comparator 16-bit latch channel 0 channel 1 internal bus logic interrupt port logic 16-bit comparator 16-bit latch channel n port logic counter reset divide by clock source off, bus, xclk, ext busclk xclk select sync interrupt interrupt interrupt 1, 2, 4, 8, 16, 32, 64, or 128 logic logic logic logic clksa clksb ps2 ps1 ps0 cpwms toie tof els0a ch0f els0b els1b els1a elsnb elsna ch1f chnf ch0ie ch1ie chnie ms1b ms0b msnb ms0a ms1a msna . . . . . . . . . tpm1modh:tpm1modl tpm1) ext clk tpm1c0vh:tpm1c0vl tpm1c1vh:tpm1c1vl tpm1cnvh:tpm1cnvl tpm1chn tpm1ch1 tpm1ch0
timer/pwm (tpm) module mc9s08rc/rd/re/rg 130 freescale semiconductor the central component of the tpm is the 16-bit counter that can operate as a free-running counter, a modulo counter, or an up-/down-counter when the tpm is con?ured for center-aligned pwm. the tpm counter (when operating in normal up-counting mode) provides the timing reference for the input capture, output compare, and edge-aligned pwm functions. the timer counter modulo registers, tpm1modh:tpm1modl, control the modulo value of the counter. (the values $0000 or $ffff effectively make the counter free running.) software can read the counter value at any time without affecting the counting sequence. any write to either byte of the tpm1cnt counter resets the counter regardless of the data value written. all tpm channels are programmable independently as input capture, output compare, or buffered edge-aligned pwm channels. 10.4 pin descriptions table 10-1 shows the mcu pins related to the tpm modules. when tpm1ch0 is used as an external clock input, the associated tpm channel 0 can not use the pin. (channel 0 can still be used in output compare mode as a software timer.) when any of the pins associated with the timer is con?ured as a timer input, a passive pullup can be enabled. after reset, the tpm modules are disabled and all pins default to general-purpose inputs with the passive pullups disabled. 10.4.1 external tpm clock sources when control bits clksb:clksa in the timer status and control register are set to 1:1, the prescaler and consequently the 16-bit counter for tpm1 are driven by an external clock source connected to the tpm1ch0 pin. a synchronizer is needed between the external clock and the rest of the tpm. this synchronizer is clocked by the bus clock so the frequency of the external source must be less than one-half the frequency of the bus rate clock. the upper frequency limit for this external clock source is speci?d to be one-fourth the bus frequency to conservatively accommodate duty cycle and phase-locked loop (pll) or frequency-locked loop (fll) frequency jitter effects. when the tpm is using the channel 0 pin for an external clock, the corresponding els0b:els0a control bits should be set to 0:0 so channel 0 is not trying to use the same pin. 10.4.2 tpm1chn ?tpm1 channel n i/o pins each tpm channel is associated with an i/o pin on the mcu. the function of this pin depends on the con?uration of the channel. in some cases, no pin function is needed so the pin reverts to being controlled by general-purpose i/o controls. when a timer has control of a port pin, the port data and data direction registers do not affect the related pin(s). see the pins and connections section for additional information about shared pin functions. 10.5 functional description all tpm functions are associated with a main 16-bit counter that allows ?xible selection of the clock source and prescale divisor. a 16-bit modulo register also is associated with the main 16-bit counter in the tpm. each tpm channel is optionally associated with an mcu pin and a maskable interrupt function.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 131 mc9s08rc/rd/re/rg the tpm has center-aligned pwm capabilities controlled by the cpwms control bit in tpm1sc. when cpwms is set to 1, timer counter tpm1cnt changes to an up-/down-counter and all channels in the associated tpm act as center-aligned pwm channels. when cpwms = 0, each channel can independently be con?ured to operate in input capture, output compare, or buffered edge-aligned pwm mode. the following sections describe the main 16-bit counter and each of the timer operating modes (input capture, output compare, edge-aligned pwm, and center-aligned pwm). because details of pin operation and interrupt activity depend on the operating mode, these topics are covered in the associated mode sections. 10.5.1 counter all timer functions are based on the main 16-bit counter (tpm1cnth:tpm1cntl). this section discusses selection of the clock source, up-counting vs. up-/down-counting, end-of-count over?w, and manual counter reset. after any mcu reset, clksb:clksa = 0:0 so no clock source is selected and the tpm is inactive. normally, clksb:clksa would be set to 0:1 so the bus clock drives the timer counter. the clock source for each of the tpm can be independently selected to be off, the bus clock (busclk), the ?ed system clock (xclk), or an external input through the tpm1ch0 pin. the maximum frequency allowed for the external clock option is one-fourth the bus rate. refer to 10.7.1 timer x status and control register (tpm1sc) and table 10-1 for more information about clock source selection. when the microcontroller is in active background mode, the tpm temporarily suspends all counting until the microcontroller returns to normal user operating mode. during stop mode, all tpm clocks are stopped; therefore, the tpm is effectively disabled until clocks resume. during wait mode, the tpm continues to operate normally. the main 16-bit counter has two counting modes. when center-aligned pwm is selected (cpwms = 1), the counter operates in up-/down-counting mode. otherwise, the counter operates as a simple up-counter. as an up-counter, the main 16-bit counter counts from $0000 through its terminal count and then continues with $0000. the terminal count is $ffff or a modulus value in tpm1modh:tpm1modl. when center-aligned pwm operation is speci?d, the counter counts upward from $0000 through its terminal count and then counts downward to $0000 where it returns to up-counting. both $0000 and the terminal count value (value in tpm1modh:tpm1modl) are normal length counts (one timer clock period long). an interrupt ?g and enable are associated with the main 16-bit counter. the timer over?w ?g (tof) is a software-accessible indication that the timer counter has over?wed. the enable signal selects between software polling (toie = 0) where no hardware interrupt is generated, or interrupt-driven operation (toie = 1) where a static hardware interrupt is automatically generated whenever the tof ?g is 1. the conditions that cause tof to become set depend on the counting mode (up or up/down). in up-counting mode, the main 16-bit counter counts from $0000 through $ffff and over?ws to $0000 on the next counting clock. tof becomes set at the transition from $ffff to $0000. when a modulus limit is set, tof becomes set at the transition from the value set in the modulus register to $0000. when the main 16-bit counter is operating in up-/down-counting mode, the tof ?g gets set as the counter changes
timer/pwm (tpm) module mc9s08rc/rd/re/rg 132 freescale semiconductor direction at the transition from the value set in the modulus register and the next lower count value. this corresponds to the end of a pwm period. (the $0000 count value corresponds to the center of a period.) because the hcs08 mcu is an 8-bit architecture, a coherency mechanism is built into the timer counter for read operations. whenever either byte of the counter is read (tpm1cnth or tpm1cntl), both bytes are captured into a buffer so when the other byte is read, the value will represent the other byte of the count at the time the ?st byte was read. the counter continues to count normally, but no new value can be read from either byte until both bytes of the old count have been read. the main timer counter can be reset manually at any time by writing any value to either byte of the timer count tpm1cnth or tpm1cntl. resetting the counter in this manner also resets the coherency mechanism in case only one byte of the counter was read before resetting the count. 10.5.2 channel mode selection provided cpwms = 0 (center-aligned pwm operation is not speci?d), the msnb and msna control bits in the channel n status and control registers determine the basic mode of operation for the corresponding channel. choices include input capture, output compare, and buffered edge-aligned pwm. 10.5.2.1 input capture mode with the input capture function, the tpm can capture the time at which an external event occurs. when an active edge occurs on the pin of an input capture channel, the tpm latches the contents of the tpm counter into the channel value registers (tpm1cnvh:tpm1cnvl). rising edges, falling edges, or any edge may be chosen as the active edge that triggers an input capture. when either byte of the 16-bit capture register is read, both bytes are latched into a buffer to support coherent 16-bit accesses regardless of order. the coherency sequence can be manually reset by writing to the channel status/control register (tpm1cnsc). an input capture event sets a ?g bit (chnf) that can optionally generate a cpu interrupt request. 10.5.2.2 output compare mode with the output compare function, the tpm can generate timed pulses with programmable position, polarity, duration, and frequency. when the counter reaches the value in the channel value registers of an output compare channel, the tpm can set, clear, or toggle the channel pin. in output compare mode, values are transferred to the corresponding timer channel value registers only after both 8-bit bytes of a 16-bit register have been written. this coherency sequence can be manually reset by writing to the channel status/control register (tpm1cnsc). an output compare event sets a ?g bit (chnf) that can optionally generate a cpu interrupt request. 10.5.2.3 edge-aligned pwm mode this type of pwm output uses the normal up-counting mode of the timer counter (cpwms = 0) and can be used when other channels in the same tpm are con?ured for input capture or output compare functions. the period of this pwm signal is determined by the setting in the modulus register (tpm1modh:tpm1modl). the duty cycle is determined by the setting in the timer channel value
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 133 mc9s08rc/rd/re/rg register (tpm1cnvh:tpm1cnvl). the polarity of this pwm signal is determined by the setting in the elsna control bit. duty cycle cases of 0 percent and 100 percent are possible. as figure 10-3 shows, the output compare value in the tpm channel registers determines the pulse width (duty cycle) of the pwm signal. the time between the modulus over?w and the output compare is the pulse width. if elsna = 0, the counter over?w forces the pwm signal high and the output compare forces the pwm signal low. if elsna = 1, the counter over?w forces the pwm signal low and the output compare forces the pwm signal high. figure 10-3 pwm period and pulse width (elsna = 0) when the channel value register is set to $0000, the duty cycle is 0 percent. by setting the timer channel value register (tpm1cnvh:tpm1cnvl) to a value greater than the modulus setting, 100 percent duty cycle can be achieved. this implies that the modulus setting must be less than $ffff to get 100 percent duty cycle. because the hcs08 is a family of 8-bit mcus, the settings in the timer channel registers are buffered to ensure coherent 16-bit updates and to avoid unexpected pwm pulse widths. writes to either register, tpm1cnvh or tpm1cnvl, write to buffer registers. in edge-pwm mode, values are transferred to the corresponding timer channel registers only after both 8-bit bytes of a 16-bit register have been written and the value in the tpm1cnth:tpm1cntl counter is $0000. (the new duty cycle does not take effect until the next full period.) 10.5.3 center-aligned pwm mode this type of pwm output uses the up-/down-counting mode of the timer counter (cpwms = 1). the output compare value in tpm1cnvh:tpm1cnvl determines the pulse width (duty cycle) of the pwm signal and the period is determined by the value in tpm1modh:tpm1modl. tpm1modh:tpm1modl should be kept in the range of $0001 to $7fff because values outside this range can produce ambiguous results. elsna will determine the polarity of the cpwm output. equation 1: pulse width = 2 x (tpm1cnvh:tpm1cnvl) equation 2: period = 2 x (tpm1modh:tpm1modl); for tpm1modh:tpm1modl = $0001?7fff if the channel value register tpm1cnvh:tpm1cnvl is zero or negative (bit 15 set), the duty cycle will be 0 percent. if tpm1cnvh:tpm1cnvl is a positive value (bit 15 clear) and is greater than the (nonzero) modulus setting, the duty cycle will be 100 percent because the duty cycle compare will never occur. this period pulse width overflow overflow overflow output compare output compare output compare tpm1chn
timer/pwm (tpm) module mc9s08rc/rd/re/rg 134 freescale semiconductor implies the usable range of periods set by the modulus register is $0001 through $7ffe ($7fff if generation of 100 percent duty cycle is not necessary). this is not a signi?ant limitation because the resulting period is much longer than required for normal applications. tpm1modh:tpm1modl = $0000 is a special case that should not be used with center-aligned pwm mode. when cpwms = 0, this case corresponds to the counter running free from $0000 through $ffff, but when cpwms = 1 the counter needs a valid match to the modulus register somewhere other than at $0000 in order to change directions from up-counting to down-counting. figure 10-4 shows the output compare value in the tpm channel registers (multiplied by 2), which determines the pulse width (duty cycle) of the cpwm signal. if elsna = 0, the compare match while counting up forces the cpwm output signal low and a compare match while counting down forces the output high. the counter counts up until it reaches the modulo setting in tpm1modh:tpm1modl, then counts down until it reaches zero. this sets the period equal to two times tpm1modh:tpm1modl. figure 10-4 cpwm period and pulse width (elsna = 0) center-aligned pwm outputs typically produce less noise than edge-aligned pwms because fewer i/o pin transitions are lined up at the same system clock edge. this type of pwm is also required for some types of motor drives. because the hcs08 is a family of 8-bit mcus, the settings in the timer channel registers are buffered to ensure coherent 16-bit updates and to avoid unexpected pwm pulse widths. writes to any of the registers, tpm1modh, tpm1modl, tpm1cnvh, and tpm1cnvl, actually write to buffer registers. values are transferred to the corresponding timer channel registers only after both 8-bit bytes of a 16-bit register have been written and the timer counter over?ws (reverses direction from up-counting to down-counting at the end of the terminal count in the modulus register). this tpm1cnt over?w requirement only applies to pwm channels, not output compares. optionally, when tpm1cnth:tpm1cntl = tpm1modh:tpm1modl, the tpm can generate a tof interrupt at the end of this count. the user can choose to reload any number of the pwm buffers, and they will all update simultaneously at the start of a new period. writing to tpm1sc cancels any values written to tpm1modh and/or tpm1modl and resets the coherency mechanism for the modulo registers. writing to tpm1cnsc cancels any values written to the channel value registers and resets the coherency mechanism for tpm1cnvh:tpm1cnvl. period pulse width count = count = 0 output compare (count up) output compare (count down) count = tpm1modh:tpm1modl tpm1chn tpm1modh:tpm1modl 2 x tpm1cnvh:tpm1cnvl 2 x tpm1modh:tpm1modl
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 135 mc9s08rc/rd/re/rg 10.6 tpm interrupts the tpm generates an optional interrupt for the main counter over?w and an interrupt for each channel. the meaning of channel interrupts depends on the mode of operation for each channel. if the channel is con?ured for input capture, the interrupt ?g is set each time the selected input capture edge is recognized. if the channel is con?ured for output compare or pwm modes, the interrupt ?g is set each time the main timer counter matches the value in the 16-bit channel value register. see the resets, interrupts, and system con?uration section for absolute interrupt vector addresses, priority, and local interrupt mask control bits. for each interrupt source in the tpm, a ?g bit is set on recognition of the interrupt condition such as timer over?w, channel input capture, or output compare events. this ?g may be read (polled) by software to verify that the action has occurred, or an associated enable bit (toie or chnie) can be set to enable hardware interrupt generation. while the interrupt enable bit is set, a static interrupt will be generated whenever the associated interrupt ?g equals 1. it is the responsibility of user software to perform a sequence of steps to clear the interrupt ?g before returning from the interrupt service routine. 10.6.1 clearing timer interrupt flags tpm interrupt ?gs are cleared by a 2-step process that includes a read of the ?g bit while it is set (1) followed by a write of 0 to the bit. if a new event is detected between these two steps, the sequence is reset and the interrupt ?g remains set after the second step to avoid the possibility of missing the new event. 10.6.2 timer overflow interrupt description the conditions that cause tof to become set depend on the counting mode (up or up/down). in up-counting mode, the 16-bit timer counter counts from $0000 through $ffff and over?ws to $0000 on the next counting clock. tof becomes set at the transition from $ffff to $0000. when a modulus limit is set, tof becomes set at the transition from the value set in the modulus register to $0000. when the counter is operating in up-/down-counting mode, the tof ?g gets set as the counter changes direction at the transition from the value set in the modulus register and the next lower count value. this corresponds to the end of a pwm period. (the $0000 count value corresponds to the center of a period.) 10.6.3 channel event interrupt description the meaning of channel interrupts depends on the current mode of the channel (input capture, output compare, edge-aligned pwm, or center-aligned pwm). when a channel is con?ured as an input capture channel, the elsnb:elsna control bits select rising edges, falling edges, any edge, or no edge (off) as the edge that triggers an input capture event. when the selected edge is detected, the interrupt ?g is set. the ?g is cleared by the 2-step sequence described in 10.6.1 clearing timer interrupt flags . when a channel is con?ured as an output compare channel, the interrupt ?g is set each time the main timer counter matches the 16-bit value in the channel value register. the ?g is cleared by the 2-step sequence described in 10.6.1 clearing timer interrupt flags .
timer/pwm (tpm) module mc9s08rc/rd/re/rg 136 freescale semiconductor 10.6.4 pwm end-of-duty-cycle events for channels that are con?ured for pwm operation, there are two possibilities: when the channel is con?ured for edge-aligned pwm, the channel ?g is set when the timer counter matches the channel value register that marks the end of the active duty cycle period. when the channel is con?ured for center-aligned pwm, the timer count matches the channel value register twice during each pwm cycle. in this cpwm case, the channel ?g is set at the start and at the end of the active duty cycle, which are the times when the timer counter matches the channel value register. the ?g is cleared by the 2-step sequence described in 10.6.1 clearing timer interrupt flags . 10.7 tpm registers and control bits the tpm includes: an 8-bit status and control register (tpm1sc) a 16-bit counter (tpm1cnth:tpm1cntl) a 16-bit modulo register (tpm1modh:tpm1modl) each timer channel has: an 8-bit status and control register (tpm1cnsc) a 16-bit channel value register (tpm1cnvh:tpm1cnvl) refer to the direct-page register summary in the memory section of this data sheet for the absolute address assignments for all tpm registers. this section refers to registers and control bits only by their names. a freescale-provided equate or header ?e is used to translate these names into the appropriate absolute addresses. some mcu systems have more than one tpm, so register names include placeholder characters to identify which tpm and which channel is being referenced. for example, tpmxcnsc refers to timer (tpm) x, channel n and tpm1c2sc is the status and control register for timer 1, channel 2. 10.7.1 timer x status and control register (tpm1sc) tpm1sc contains the over?w status ?g and control bits that are used to con?ure the interrupt enable, tpm con?uration, clock source, and prescale divisor. these controls relate to all channels within this timer module.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 137 mc9s08rc/rd/re/rg figure 10-5 timer x status and control register (tpm1sc) tof timer overflow flag this flag is set when the tpm counter changes to $0000 after reaching the modulo value programmed in the tpm counter modulo registers. when the tpm is configured for cpwm, tof is set after the counter has reached the value in the modulo register, at the transition to the next lower count value. clear tof by reading the tpm status and control register when tof is set and then writing a logic 0 to tof. if another tpm overflow occurs before the clearing sequence is complete, the sequence is reset so tof would remain set after the clear sequence was completed for the earlier tof. reset clears the tof bit. writing a logic 1 to tof has no effect. 1 = tpm counter has overflowed. 0 = tpm counter has not reached modulo value or overflow. toie timer overflow interrupt enable this read/write bit enables tpm overflow interrupts. if toie is set, an interrupt is generated when tof equals 1. reset clears toie. 1 = tof interrupts enabled. 0 = tof interrupts inhibited (use software polling). cpwms center-aligned pwm select this read/write bit selects cpwm operating mode. reset clears this bit so the tpm operates in up-counting mode for input capture, output compare, and edge-aligned pwm functions. setting cpwms reconfigures the tpm to operate in up-/down-counting mode for cpwm functions. reset clears the cpwms bit. 1 = all tpm1 channels operate in center-aligned pwm mode. 0 = all tpm1 channels operate as input capture, output compare, or edge-aligned pwm mode as selected by the msnb:msna control bits in each channel? status and control register. clksb:clksa clock source select as shown in table 10-1 , this 2-bit field is used to disable the tpm system or select one of three clock sources to drive the counter prescaler. the external source and the crystal source are synchronized to the bus clock by an on-chip synchronization circuit. bit 7 654321 bit 0 read: tof toie cpwms clksb clksa ps2 ps1 ps0 write: reset: 00000000 = unimplemented or reserved
timer/pwm (tpm) module mc9s08rc/rd/re/rg 138 freescale semiconductor ps2:ps1:ps0 prescale divisor select this 3-bit field selects one of eight divisors for the tpm clock input as shown in table 10-2 . this prescaler is located after any clock source synchronization or clock source selection, so it affects whatever clock source is selected to drive the tpm system. 10.7.2 timer x counter registers (tpm1cnth:tpm1cntl) the two read-only tpm counter registers contain the high and low bytes of the value in the tpm counter. reading either byte (tpm1cnth or tpm1cntl) latches the contents of both bytes into a buffer where they remain latched until the other byte is read. this allows coherent 16-bit reads in either order. the coherency mechanism is automatically restarted by an mcu reset, a write of any value to tpm1cnth or tpm1cntl, or any write to the timer status/control register (tpm1sc). reset clears the tpm counter registers. table 10-1 tpm clock source selection clksb:clksa tpm clock source to prescaler input 0:0 no clock selected (tpm disabled) 0:1 bus rate clock (busclk) 1:0 fixed system clock (xclk) 1:1 external source (tpm1 ext clk) 12 1 the maximum frequency that is allowed as an external clock is one-fourth of the bus frequency. 2 when the tpm1ch0 pin is selected as the tpm clock source, the corresponding els0b:els0a control bits should be set to 0:0 so channel 0 does not try to use the same pin for a con?cting function. table 10-2 prescale divisor selection ps2:ps1:ps0 tpm clock source divided-by 0:0:0 1 0:0:1 2 0:1:0 4 0:1:1 8 1:0:0 16 1:0:1 32 1:1:0 64 1:1:1 128
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 139 mc9s08rc/rd/re/rg figure 10-6 timer x counter register high (tpm1cnth) figure 10-7 timer x counter register low (tpm1cntl) when background mode is active, the timer counter and the coherency mechanism are frozen such that the buffer latches remain in the state they were in when the background mode became active even if one or both bytes of the counter are read while background mode is active. 10.7.3 timer x counter modulo registers (tpm1modh:tpm1modl) the read/write tpm modulo registers contain the modulo value for the tpm counter. after the tpm counter reaches the modulo value, the tpm counter resumes counting from $0000 at the next clock (cpwms = 0) or starts counting down (cpwms = 1), and the over?w ?g (tof) becomes set. writing to tpm1modh or tpm1modl inhibits the tof bit and over?w interrupts until the other byte is written. reset sets the tpm counter modulo registers to $0000, which results in a free-running timer counter (modulo disabled). figure 10-8 timer x counter modulo register high (tpm1modh) bit 7 654321 bit 0 read: bit 15 14 13 12 11 10 9 bit 8 write: any write to tpm1cnth clears the 16-bit counter. reset: 00000000 bit 7 654321 bit 0 read: bit 7 654321 bit 0 write: any write to tpm1cntl clears the 16-bit counter. reset: 00000000 bit 7 654332 bit 0 read: bit 15 14 13 12 11 10 9 bit 8 write: reset: 00000000
timer/pwm (tpm) module mc9s08rc/rd/re/rg 140 freescale semiconductor figure 10-9 timer x counter modulo register low (tpm1modl) it is good practice to wait for an over?w interrupt so both bytes of the modulo register can be written well before a new over?w. an alternative approach is to reset the tpm counter before writing to the tpm modulo registers to avoid confusion about when the ?st counter over?w will occur. 10.7.4 timer x channel n status and control register (tpm1cnsc) tpm1cnsc contains the channel interrupt status ?g and control bits that are used to con?ure the interrupt enable, channel con?uration, and pin function. figure 10-10 timer x channel n status and control register (tpm1cnsc) chnf channel n flag when channel n is configured for input capture, this flag bit is set when an active edge occurs on the channel n pin. when channel n is an output compare or edge-aligned pwm channel, chnf is set when the value in the tpm counter registers matches the value in the tpm channel n value registers. this flag is seldom used with center-aligned pwms because it is set every time the counter matches the channel value register, which correspond to both edges of the active duty cycle period. a corresponding interrupt is requested when chnf is set and interrupts are enabled (chnie = 1). clear chnf by reading tpm1cnsc while chnf is set and then writing a logic 0 to chnf. if another interrupt request occurs before the clearing sequence is complete, the sequence is reset so chnf would remain set after the clear sequence was completed for the earlier chnf. this is done so a chnf interrupt request cannot be lost by clearing a previous chnf. reset clears the chnf bit. writing a logic 1 to chnf has no effect. 1 = input capture or output compare event occurred on channel n. 0 = no input capture or output compare event occurred on channel n. bit 7 654321 bit 0 read: bit 7 654321 bit 0 write: reset: 00000000 bit 7 654321 bit 0 read: chnf chnie msnb msna elsnb elsna 00 write: reset: 00000000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 141 mc9s08rc/rd/re/rg chnie channel n interrupt enable this read/write bit enables interrupts from channel n. reset clears the chnie bit. 1 = channel n interrupt requests enabled. 0 = channel n interrupt requests disabled (use software polling). msnb mode select b for tpm channel n when cpwms = 0, msnb = 1 configures tpm channel n for edge-aligned pwm mode. for a summary of channel mode and setup controls, refer to table 10-3 . msna mode select a for tpm channel n when cpwms = 0 and msnb = 0, msna configures tpm channel n for input capture mode or output compare mode. refer to table 10-3 for a summary of channel mode and setup controls. if the associated port pin is not stable for at least two bus clock cycles before changing to input capture mode, it is possible to get an unexpected indication of an edge trigger. typically, a program would clear status ?gs after changing channel con?uration bits and before enabling channel interrupts or using the status ?gs to avoid any unexpected behavior. elsnb:elsna edge/level select bits depending on the operating mode for the timer channel as set by cpwms:msnb:msna and shown in table 10-3 , these bits select the polarity of the input edge that triggers an input capture event, select the level that will be driven in response to an output compare match, or select the polarity of the pwm output. table 10-3 mode, edge, and level selection cpwms msnb:msna elsnb:elsna mode con?uration xxx 00 pin not used for tpm channel; use as an external clock for the tpm or revert to general-purpose i/o 0 00 01 input capture capture on rising edge only 10 capture on falling edge only 11 capture on rising or falling edge 01 01 output compare toggle output on compare 10 clear output on compare 11 set output on compare 1x 10 edge-aligned pwm high-true pulses (clear output on compare) x1 low-true pulses (set output on compare) 1xx 10 center-aligned pwm high-true pulses (clear output on compare-up) x1 low-true pulses (set output on compare-up)
timer/pwm (tpm) module mc9s08rc/rd/re/rg 142 freescale semiconductor setting elsnb:elsna to 0:0 configures the related timer pin as a general-purpose i/o pin unrelated to any timer channel functions. this function is typically used to temporarily disable an input capture channel or to make the timer pin available as a general-purpose i/o pin when the associated timer channel is set up as a software timer that does not require the use of a pin. this is also the setting required for channel 0 when the tpm1ch0 pin is used as an external clock input. 10.7.5 timer x channel value registers (tpm1cnvh:tpm1cnvl) these read/write registers contain the captured tpm counter value of the input capture function or the output compare value for the output compare or pwm functions. the channel value registers are cleared by reset. figure 10-11 timer x channel value register high (tpm1cnvh) figure 10-12 timer x channel value register low (tpm1cnvl) in input capture mode, reading either byte (tpm1cnvh or tpm1cnvl) latches the contents of both bytes into a buffer where they remain latched until the other byte is read. this latching mechanism also resets (becomes unlatched) when the tpm1cnsc register is written. in output compare or pwm modes, writing to either byte (tpm1cnvh or tpm1cnvl) latches the value into a buffer. when both bytes have been written, they are transferred as a coherent 16-bit value into the timer channel value registers. this latching mechanism may be manually reset by writing to the tpm1cnsc register. this latching mechanism allows coherent 16-bit writes in either order, which is friendly to various compiler implementations. bit 7 654321 bit 0 read: bit 15 14 13 12 11 10 9 bit 8 write: reset: 00000000 bit 7 654321 bit 0 read: bit 7 654321 bit 0 write: reset: 00000000
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 143 mc9s08rc/rd/re/rg chapter 11 serial communications interface (sci) module the mc9s08rdxx, mc9s08rexx, and mc9s08rgxx devices include a serial communications interface (sci) module, which is sometimes called a universal asynchronous receiver/transmitters (uart). the sci module shares pins with ptb0 and ptb1 port pins. when the sci is enabled, the pins are controlled by the sci module. figure 11-1 mc9s08rc/rd/re/rg block diagram highlighting sci block and pins ptd3 ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 ptc1/kbi2p1 ptc0/kbi2p0 v ss v dd ptb3 ptb2 pta7/kbi1p7 ptb0/ txd1 ptb1/ rxd1 ptd2/irq ptd1/ reset ptd0/bkgd/ms ptc7/ ss1 ptc6/spsck1 ptc5/miso1 ptc4/mosi1 ptc3/kbi2p3 ptc2/kbi2p2 port a port c port d port b 8-bit keyboard interrupt module (kbi1) serial peripheral interface module (spi1) user flash user ram (rc/rd/re/rg32/60 = 2048 bytes) debug module (dbg) (rc/rd/re/rg60 = 63,364 bytes) hcs08 core notes: 1. port pins are software configurable with pullup device if input port 2. pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . 3. irq pin contains software configurable pullup/pulldown device if irq enabled (irqpe = 1) 4. the reset pin contains integrated pullup device enabled if reset enabled (rstpe = 1) 5. high current drive 6. pins pta[7:0] contain both pullup and pulldown devices. pulldown available when kbi enabled (kbi1pn = 1). notes notes 1, 5 2-channel timer/pwm module (tpm1) pte7 port e ptb5 ptb4 pte6 ptb7/tpm1ch1 module (acmp1) hcs08 system control resets and interrupts modes of operation power management voltage regulator rti analog comparator cop irq lvd internal bus low-power oscillator interface module (sci1) serial communications 7 pta1/kbi1p1 8 pte0 note 1 notes1, 2 note 1 (rc/rd/re/rg32 = 32,768 bytes) (rc/rd/re8/16 = 1024 bytes) (rc/rd/re16 = 16,384 bytes) xtal extal carrier modulator timer module (cmt) 1, 3, 4 4-bit keyboard interrupt module (kbi2) iro note 5 pta0/kbi1p0 (rc/rd/re8 = 8192 bytes) bdc cpu
serial communications interface (sci) module mc9s08rc/rd/re/rg 144 freescale semiconductor 11.1 features features of sci module include: full-duplex, standard non-return-to-zero (nrz) format double-buffered transmitter and receiver with separate enables programmable baud rates (13-bit modulo divider) interrupt-driven or polled operation: transmit data register empty and transmission complete receive data register full receive overrun, parity error, framing error, and noise error idle receiver detect hardware parity generation and checking programmable 8-bit or 9-bit character length receiver wakeup by idle-line or address-mark 11.2 sci system description the sci allows full-duplex, asynchronous, nrz serial communication among the mcu and remote devices, including other mcus. the sci comprises a baud rate generator, transmitter, and receiver block. the transmitter and receiver operate independently, although they use the same baud rate generator. during normal operation, the mcu monitors the status of the sci, writes the data to be transmitted, and processes received data. the following describes each of the blocks of the sci. 11.3 baud rate generation as shown in figure 11-2 , the clock source for the sci baud rate generator is the bus-rate clock. figure 11-2 sci baud rate generation sbr12:sbr0 divide by tx baud rate rx sampling clock (16 baud rate) baud rate generator off if [sbr12:sbr0] = 0 busclk baud rate = busclk [sbr12:sbr0] 16 16 modulo divide by (1 through 8191)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 145 mc9s08rc/rd/re/rg sci communications require the transmitter and receiver (which typically derive baud rates from independent clock sources) to use the same baud rate. allowed tolerance on this baud frequency depends on the details of how the receiver synchronizes to the leading edge of the start bit and how bit sampling is performed. the mc9s08rc/rd/re/rg resynchronizes to bit boundaries on every high-to-low transition, but in the worst case, there are no such transitions in the full 10- or 11-bit time character frame so any mismatch in baud rate is accumulated for the whole character time. for a freescale semiconductor sci system whose bus frequency is driven by a crystal, the allowed baud rate mismatch is about 4.5 percent for 8-bit data format and about 4 percent for 9-bit data format. although baud rate modulo divider settings do not always produce baud rates that exactly match standard rates, it is normally possible to get within a few percent, which is acceptable for reliable communications. 11.4 transmitter functional description this section describes the overall block diagram for the sci transmitter, as well as specialized functions for sending break and idle characters. 11.4.1 transmitter block diagram figure 11-3 shows the transmitter portion of the sci.
serial communications interface (sci) module mc9s08rc/rd/re/rg 146 freescale semiconductor figure 11-3 sci transmitter block diagram the transmitter is enabled by setting the te bit in sci1c2. this queues a preamble character that is one full character frame of logic high. the transmitter then remains idle (txd1 pin remains high) until data is available in the transmit data buffer. programs store data into the transmit data buffer by writing to the sci data register (sci1d). the central element of the sci transmitter is the transmit shift register that is either 10 or 11 bits long depending on the setting in the m control bit. for the remainder of this section, we will assume m = 0, selecting the normal 8-bit data mode. in 8-bit data mode, the shift register holds a start bit, eight data bits, and a stop bit. when the transmit shift register is available for a new sci character, the value waiting in the transmit data register is transferred to the shift register (synchronized with the baud rate clock) and the transmit data register empty (tdre) status flag is set to indicate another character may be written to the transmit data buffer at sci1d. h 8 7 6 5 4 3 2 1 0 l scid ?tx buffer (write-only) internal bus stop 11-bit transmit shift register start shift direction lsb 1 baud rate clock parity generation transmit control shift enable preamble (all 1s) break (all 0s) enable sci controls txd1 txd1 direction to txd1 pin logic loop control to receive data in to txd1 pin tx interrupt request loops rsrc tie tc tdre m pt pe tcie te sbk t8 txdir load from sci1d
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 147 mc9s08rc/rd/re/rg if no new character is waiting in the transmit data buffer after a stop bit is shifted out the txd1 pin, the transmitter sets the transmit complete flag and enters an idle mode, with txd1 high, waiting for more characters to transmit. writing 0 to te does not immediately release the pin to be a general-purpose i/o pin. any transmit activity that is in progress must first be completed. this includes data characters in progress, queued idle characters, and queued break characters. 11.4.2 send break and queued idle the sbk control bit in sci1c2 is used to send break characters that were originally used to gain the attention of old teletype receivers. break characters are a full character time of logic 0 (including a 0 where the stop bit would be normally). normally, a program would wait for tdre to become set to indicate the last character of a message has moved to the transmit shifter, then write 1 and then write 0 to the sbk bit. this action queues a break character to be sent as soon as the shifter is available. if sbk is still 1 when the queued break moves into the shifter (synchronized to the baud rate clock), an additional break character is queued. if the receiving device is another freescale semiconductor sci, the break characters will be received as 0s in all eight (or nine) data bits and a framing error (fe = 1). when idle-line wakeup is used, a full character time of idle (logic 1) is needed between messages to wake up any sleeping receivers. normally, a program would wait for tdre to become set to indicate the last character of a message has moved to the transmit shifter, then write 0 and then write 1 to the te bit. this action queues an idle character to be sent as soon as the shifter is available. as long as the character in the shifter does not finish while te = 0, the sci transmitter never actually releases control of the txd1 pin. if there is a possibility of the shifter finishing while te = 0, set the general-purpose i/o controls so the pin that is shared with txd1 is an output driving a logic 1. this ensures that the txd1 line will look like a normal idle line even if the sci loses control of the port pin between writing 0 and then 1 to te. 11.5 receiver functional description in this section, the receiver block diagram ( figure 11-4 ) is used as a guide for the overall receiver functional description. next, the data sampling technique used to reconstruct receiver data is described in more detail. finally, two variations of the receiver wakeup function are explained. 11.5.1 receiver block diagram figure 11-4 shows the receiver portion of the sci.
serial communications interface (sci) module mc9s08rc/rd/re/rg 148 freescale semiconductor figure 11-4 sci receiver block diagram the receiver is enabled by setting the re bit in sci1c2. character frames consist of a start bit of logic 0, eight (or nine) data bits (lsb first), and a stop bit of logic 1. for information about 9-bit data mode, refer to 11.7.1 8- and 9-bit data modes . for the remainder of this discussion, we assume the sci is configured for normal 8-bit data mode. h 8 7 6 5 4 3 2 1 0 l scid ?rx buffer (read-only) internal bus stop 11-bit receive shift register start shift direction lsb from rxd1 pin rate clock rx interrupt request data recovery divide 16 baud single-wire loop control wakeup logic all 1s msb from transmitter error interrupt request parity checking by 16 rdrf rie idle ilie or orie fe feie nf neie pf loops peie pt pe rsrc wake ilt rwu m
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 149 mc9s08rc/rd/re/rg after receiving the stop bit into the receive shifter, and provided the receive data register is not already full, the data character is transferred to the receive data register and the receive data register full (rdrf) status flag is set. if rdrf was already set indicating the receive data register (buffer) was already full, the overrun (or) status flag is set and the new data is lost. because the sci receiver is double-buffered, the program has one full character time after rdrf is set before the data in the receive data buffer must be read to avoid a receiver overrun. when a program detects that the receive data register is full (rdrf = 1), it gets the data from the receive data register by reading sci1d. the rdrf flag is cleared automatically by a 2-step sequence (which is normally satisfied in the course of the user? program that handles receive data). refer to 11.6 interrupts and status flags for more details about flag clearing. 11.5.2 data sampling technique the sci receiver uses a 16 baud rate clock for sampling. the receiver starts by taking logic level samples at 16 times the baud rate to search for a falling edge on the rxd1 serial data input pin. a falling edge is defined as a logic 0 sample after three consecutive logic 1 samples. the 16 baud rate clock is used to divide the bit time into 16 segments labeled rt1 through rt16. when a falling edge is located, three more samples are taken at rt3, rt5, and rt7 to make sure this was a real start bit and not merely noise. if at least two of these three samples are 0, the receiver assumes it is synchronized to a receive character. the receiver then samples each bit time, including the start and stop bits, at rt8, rt9, and rt10 to determine the logic level for that bit. the logic level is interpreted to be that of the majority of the samples taken during the bit time. in the case of the start bit, the bit is assumed to be 0 if at least two of the samples at rt3, rt5, and rt7 are 0 even if one or all of the samples taken at rt8, rt9, and rt10 are 1s. if any sample in any bit time (including the start and stop bits) in a character frame fails to agree with the logic level for that bit, the noise flag (nf) will be set when the received character is transferred to the receive data buffer. the falling edge detection logic continuously looks for falling edges, and if an edge is detected, the sample clock is resynchronized to bit times. this improves the reliability of the receiver in the presence of noise or mismatched baud rates. it does not improve worst case analysis because some characters do not have any extra falling edges anywhere in the character frame. in the case of a framing error, provided the received character was not a break character, the sampling logic that searches for a falling edge is filled with three logic 1 samples so that a new start bit can be detected almost immediately. in the case of a framing error, the receiver is inhibited from receiving any new characters until the framing error flag is cleared. the receive shift register continues to function, but a complete character cannot transfer to the receive data buffer if fe is still set.
serial communications interface (sci) module mc9s08rc/rd/re/rg 150 freescale semiconductor 11.5.3 receiver wakeup operation receiver wakeup is a hardware mechanism that allows an sci receiver to ignore the characters in a message that is intended for a different sci receiver. in such a system, all receivers evaluate the first character(s) of each message, and as soon as they determine the message is intended for a different receiver, they write logic 1 to the receiver wake up (rwu) control bit in sci1c2. when rwu = 1, it inhibits setting of the status flags associated with the receiver, thus eliminating the software overhead for handling the unimportant message characters. at the end of a message, or at the beginning of the next message, all receivers automatically force rwu to 0 so all receivers wake up in time to look at the first character(s) of the next message. 11.5.3.1 idle-line wakeup when wake = 0, the receiver is configured for idle-line wakeup. in this mode, rwu is cleared automatically when the receiver detects a full character time of the idle-line level. the m control bit selects 8-bit or 9-bit data mode that determines how many bit times of idle are needed to constitute a full character time (10 or 11 bit times because of the start and stop bits). the idle-line type (ilt) control bit selects one of two ways to detect an idle line. when ilt = 0, the idle bit counter starts after the start bit so the stop bit and any logic 1s at the end of a character count toward the full character time of idle. when ilt = 1, the idle bit counter doesn? start until after a stop bit time, so the idle detection is not affected by the data in the last character of the previous message. 11.5.3.2 address-mark wakeup when wake = 1, the receiver is configured for address-mark wakeup. in this mode, rwu is cleared automatically when the receiver detects a logic 1 in the most significant bit of a received character (eighth bit in m = 0 mode and ninth bit in m = 1 mode). 11.6 interrupts and status flags the sci system has three separate interrupt vectors to reduce the amount of software needed to isolate the cause of the interrupt. one interrupt vector is associated with the transmitter for tdre and tc events. another interrupt vector is associated with the receiver for rdrf and idle events, and a third vector is used for or, nf, fe, and pf error conditions. each of these eight interrupt sources can be separately masked by local interrupt enable masks. the flags can still be polled by software when the local masks are cleared to disable generation of hardware interrupt requests. the sci transmitter has two status flags that optionally can generate hardware interrupt requests. transmit data register empty (tdre) indicates when there is room in the transmit data buffer to write another transmit character to sci1d. if the transmit interrupt enable (tie) bit is set, a hardware interrupt will be requested whenever tdre = 1. transmit complete (tc) indicates that the transmitter is finished transmitting all data, preamble, and break characters and is idle with txd1 high. this flag is often used in systems with modems to determine when it is safe to turn off the modem. if the transmit complete interrupt enable (tcie) bit is set, a hardware interrupt will be requested whenever tc = 1. instead of hardware interrupts, software polling may be used to monitor the tdre and tc status flags if the corresponding tie or tcie local interrupt masks are 0s.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 151 mc9s08rc/rd/re/rg when a program detects that the receive data register is full (rdrf = 1), it gets the data from the receive data register by reading sci1d. the rdrf flag is cleared by reading sci1s1 while rdrf = 1 and then reading sci1d. when polling is used, this sequence is naturally satisfied in the normal course of the user program. if hardware interrupts are used, sci1s1 must be read in the interrupt service routine (isr). normally, this is done in the isr anyway to check for receive errors, so the sequence is automatically satisfied. the idle status flag includes logic that prevents it from getting set repeatedly when the rxd1 line remains idle for an extended period of time. idle is cleared by reading sci1s1 while idle = 1 and then reading sci1d. after idle has been cleared, it cannot become set again until the receiver has received at least one new character and has set rdrf. if the associated error was detected in the received character that caused rdrf to be set, the error flags ?noise flag (nf), framing error (fe), and parity error flag (pf) ?get set at the same time as rdrf. these flags are not set in overrun cases. if rdrf was already set when a new character is ready to be transferred from the receive shifter to the receive data buffer, the overrun (or) flag gets set instead and the data and any associated nf, fe, or pf condition is lost. 11.7 additional sci functions the following sections describe additional sci functions. 11.7.1 8- and 9-bit data modes the sci system (transmitter and receiver) can be configured to operate in 9-bit data mode by setting the m control bit in sci1c1. in 9-bit mode, there is a ninth data bit to the left of the msb of the sci data register. for the transmit data buffer, this bit is stored in t8 in sci1c3. for the receiver, the ninth bit is held in r8 in sci1c3. for coherent writes to the transmit data buffer, write to the t8 bit before writing to sci1d. for coherent reads of the receive data buffer, read r8 before reading sci1d because reading or writing sci1d is the final step in automatic clearing mechanisms for sci flags. if the bit value to be transmitted as the ninth bit of a new character is the same as for the previous character, it is not necessary to write to t8 again. when data is transferred from the transmit data buffer to the transmit shifter, the value in t8 is copied at the same time data is transferred from sci1d to the shifter. 9-bit data mode typically is used in conjunction with parity to allow eight bits of data plus the parity in the ninth bit. or it is used with address-mark wakeup so the ninth data bit can serve as the wakeup bit. in custom protocols, the ninth bit can also serve as a software-controlled marker.
serial communications interface (sci) module mc9s08rc/rd/re/rg 152 freescale semiconductor 11.8 stop mode operation during all stop modes, clocks to the sci module are halted. in stop1 and stop2 modes, all sci register data is lost and must be re-initialized upon recovery from these two stop modes. no sci module registers are affected in stop3 mode. note, because the clocks are halted, the sci module will resume operation upon exit from stop (only in stop3 mode). software should ensure stop mode is not entered while there is a character being transmitted out of or received into the sci module. 11.8.1 loop mode when loops = 1, the rsrc bit in the same register chooses between loop mode (rsrc = 0) or single-wire mode (rsrc = 1). loop mode is sometimes used to check software, independent of connections in the external system, to help isolate system problems. in this mode, the transmitter output is internally connected to the receiver input and the rxd1 pin is not used by the sci, so it reverts to a general-purpose port i/o pin. 11.8.2 single-wire operation when loops = 1, the rsrc bit in the same register chooses between loop mode (rsrc = 0) or single-wire mode (rsrc = 1). single-wire mode is used to implement a half-duplex serial connection. the receiver is internally connected to the transmitter output and to the txd1 pin. the rxd1 pin is not used and reverts to a general-purpose port i/o pin. in single-wire mode, the txdir bit in sci1c3 controls the direction of serial data on the txd1 pin. when txdir = 0, the txd1 pin is an input to the sci receiver and the transmitter is temporarily disconnected from the txd1 pin so an external device can send serial data to the receiver. when txdir = 1, the txd1 pin is an output driven by the transmitter. in single-wire mode, the internal loop back connection from the transmitter to the receiver causes the receiver to receive characters that are sent out by the transmitter. 11.9 sci registers and control bits the sci has eight 8-bit registers to control baud rate, select sci options, report sci status, and for transmit/receive data. refer to the direct-page register summary in the memory section of this data sheet for the absolute address assignments for all sci registers. this section refers to registers and control bits only by their names. a freescale-provided equate or header file is used to translate these names into the appropriate absolute addresses.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 153 mc9s08rc/rd/re/rg 11.9.1 sci baud rate registers (sci1bdh, sci1bdl) this pair of registers controls the prescale divisor for sci baud rate generation. to update the 13-bit baud rate setting [sbr12:sbr0], first write to sci1bdh to buffer the high half of the new value and then write to sci1bdl. the working value in sci1bdh does not change until sci1bdl is written. sci1bdl is reset to a non-zero value, so after reset the baud rate generator remains disabled until the first time the receiver or transmitter is enabled (re or te bits in sci1c2 are written to 1). figure 11-5 sci baud rate register (sci1bdh) figure 11-6 sci baud rate register (sci1bdl) sbr12:sbr0 baud rate modulo divisor these 13 bits are referred to collectively as br, and they set the modulo divide rate for the sci baud rate generator. when br = 0, the sci baud rate generator is disabled to reduce supply current. when br = 1 to 8191, the sci baud rate = busclk/(16 br). 11.9.2 sci control register 1 (sci1c1) this read/write register is used to control various optional features of the sci system. figure 11-7 sci control register 1 (sci1c1) bit 7 654321 bit 0 read: 0 0 0 sbr12 sbr11 sbr10 sbr9 sbr8 write: reset: 00000000 = unimplemented or reserved bit 7 654321 bit 0 read: sbr7 sbr6 sbr5 sbr4 sbr3 sbr2 sbr1 sbr0 write: reset: 00000100 = unimplemented or reserved bit 7 6 54321 bit 0 read: loops sciswai rsrc m wake ilt pe pt write: reset: 0 0 000000
serial communications interface (sci) module mc9s08rc/rd/re/rg 154 freescale semiconductor loops loop mode select selects between loop back modes and normal 2-pin full-duplex modes. when loops = 1, the transmitter output is internally connected to the receiver input. 1 = loop mode or single-wire mode where transmitter outputs are internally connected to receiver input. (see rsrc bit.) rxd1 pin is not used by sci. 0 = normal operation ?rxd1 and txd1 use separate pins. sciswai sci stops in wait mode 1 = sci clocks freeze while cpu is in wait mode. 0 = sci clocks continue to run in wait mode so the sci can be the source of an interrupt that wakes up the cpu. rsrc receiver source select this bit has no meaning or effect unless the loops bit is set to 1. when loops = 1, the receiver input is internally connected to the txd1 pin and rsrc determines whether this connection is also connected to the transmitter output. 1 = single-wire sci mode where the txd1 pin is connected to the transmitter output and receiver input. 0 = provided loops = 1, rsrc = 0 selects internal loop back mode and the sci does not use the rxd1 or txd1 pins. m 9-bit or 8-bit mode select 1 = receiver and transmitter use 9-bit data characters start + 8 data bits (lsb first) + 9th data bit + stop. 0 = normal ?start + 8 data bits (lsb first) + stop. wake receiver wakeup method select refer to 11.5.3 receiver wakeup operation for more information. 1 = address-mark wakeup. 0 = idle-line wakeup. ilt idle line type select setting this bit to 1 ensures that the stop bit and logic 1 bits at the end of a character do not count toward the 10 or 11 bit times of the logic high level by the idle line detection logic. refer to 11.5.3.1 idle-line wakeup for more information. 1 = idle character bit count starts after stop bit. 0 = idle character bit count starts after start bit. pe parity enable enables hardware parity generation and checking. when parity is enabled, the most significant bit (msb) of the data character (eighth or ninth data bit) is treated as the parity bit. 1 = parity enabled. 0 = no hardware parity generation or checking.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 155 mc9s08rc/rd/re/rg pt parity type provided parity is enabled (pe = 1), this bit selects even or odd parity. odd parity means the total number of 1s in the data character, including the parity bit, is odd. even parity means the total number of 1s in the data character, including the parity bit, is even. 1 = odd parity. 0 = even parity. 11.9.3 sci control register 2 (sci1c2) this register can be read or written at any time. figure 11-8 sci control register 2 (sci1c2) tie transmit interrupt enable (for tdre) 1 = hardware interrupt requested when tdre flag is 1. 0 = hardware interrupts from tdre disabled (use polling). tcie transmission complete interrupt enable (for tc) 1 = hardware interrupt requested when tc flag is 1. 0 = hardware interrupts from tc disabled (use polling). rie receiver interrupt enable (for rdrf) 1 = hardware interrupt requested when rdrf flag is 1. 0 = hardware interrupts from rdrf disabled (use polling). ilie idle line interrupt enable (for idle) 1 = hardware interrupt requested when idle flag is 1. 0 = hardware interrupts from idle disabled (use polling). te transmitter enable 1 = transmitter on. 0 = transmitter off. te must be 1 in order to use the sci transmitter. normally, when te = 1, the sci forces the txd1 pin to act as an output for the sci system. if loops = 1 and rsrc = 0, the txd1 pin reverts to being a port b general-purpose i/o pin even if te = 1. when the sci is configured for single-wire operation (loops = rsrc = 1), txdir controls the direction of traffic on the single sci communication line (txd1 pin). te also can be used to queue an idle character by writing te = 0 then te = 1 while a transmission is in progress. refer to 11.4.2 send break and queued idle for more details. bit 7 654321 bit 0 read: tie tcie rie ilie te re rwu sbk write: reset: 00000000
serial communications interface (sci) module mc9s08rc/rd/re/rg 156 freescale semiconductor when te is written to 0, the transmitter keeps control of the port txd1 pin until any data, queued idle, or queued break character finishes transmitting before allowing the pin to revert to a general-purpose i/o pin. re receiver enable when the sci receiver is off, the rxd1 pin reverts to being a general-purpose port i/o pin. 1 = receiver on. 0 = receiver off. rwu receiver wakeup control this bit can be written to 1 to place the sci receiver in a standby state where it waits for automatic hardware detection of a selected wakeup condition. the wakeup condition is either an idle line between messages (wake = 0, idle-line wakeup), or a logic 1 in the most significant data bit in a character (wake = 1, address-mark wakeup). application software sets rwu and (normally) a selected hardware condition automatically clears rwu. refer to 11.5.3 receiver wakeup operation for more details. 1 = sci receiver in standby waiting for wakeup condition. 0 = normal sci receiver operation. sbk send break writing a 1 and then a 0 to sbk queues a break character in the transmit data stream. additional break characters of 10 or 11 bit times of logic 0 are queued as long as sbk = 1. depending on the timing of the set and clear of sbk relative to the information currently being transmitted, a second break character may be queued before software clears sbk. refer to 11.4.2 send break and queued idle for more details. 1 = queue break character(s) to be sent. 0 = normal transmitter operation. 11.9.4 sci status register 1 (sci1s1) this register has eight read-only status flags. writes have no effect. special software sequences (that do not involve writing to this register) are used to clear these status flags. figure 11-9 sci status register 1 (sci1s1) bit 7 654321 bit 0 read: tdre tc rdrf idle or nf fe pf write: reset: 11000000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 157 mc9s08rc/rd/re/rg tdre transmit data register empty flag tdre is set out of reset and when a transmit data value transfers from the transmit data buffer to the transmit shifter, leaving room for a new character in the buffer. to clear tdre, read sci1s1 with tdre = 1 and then write to the sci data register (sci1d). 1 = transmit data register (buffer) empty. 0 = transmit data register (buffer) full. tc transmission complete flag tc is set out of reset and when tdre = 1 and no data, preamble, or break character is being transmitted. 1 = transmitter idle (transmission activity complete). 0 = transmitter active (sending data, a preamble, or a break). tc is cleared automatically by reading sci1s1 with tc = 1 and then doing one of the following: write to the sci data register (sci1d) to transmit new data queue a preamble by changing te from 0 to 1 queue a break character by writing 1 to sbk in sci1c2 rdrf receive data register full flag rdrf becomes set when a character transfers from the receive shifter into the receive data register (sci1d). to clear rdrf, read sci1s1 with rdrf = 1 and then read the sci data register (sci1d). 1 = receive data register full. 0 = receive data register empty. idle idle line flag idle is set when the sci receive line becomes idle for a full character time after a period of activity. when ilt = 0, the receiver starts counting idle bit times after the start bit. so if the receive character is all 1s, these bit times and the stop bit time count toward the full character time of logic high (10 or 11 bit times depending on the m control bit) needed for the receiver to detect an idle line. when ilt = 1, the receiver doesn? start counting idle bit times until after the stop bit. so the stop bit and any logic high bit times at the end of the previous character do not count toward the full character time of logic high needed for the receiver to detect an idle line. to clear idle, read sci1s1 with idle = 1 and then read the sci data register (sci1d). after idle has been cleared, it cannot become set again until after a new character has been received and rdrf has been set. idle will be set only once even if the receive line remains idle for an extended period. 1 = idle line was detected. 0 = no idle line detected.
serial communications interface (sci) module mc9s08rc/rd/re/rg 158 freescale semiconductor or receiver overrun flag or is set when a new serial character is ready to be transferred to the receive data register (buffer), but the previously received character has not been read from sci1d yet. in this case, the new character (and all associated error information) is lost because there is no room to move it into sci1d. to clear or, read sci1s1 with or = 1 and then read the sci data register (sci1d). 1 = receive overrun (new sci data lost). 0 = no overrun. nf noise flag the advanced sampling technique used in the receiver takes seven samples during the start bit and three samples in each data bit and the stop bit. if any of these samples disagrees with the rest of the samples within any bit time in the frame, the flag nf will be set at the same time as the flag rdrf gets set for the character. to clear nf, read sci1s1 and then read the sci data register (sci1d). 1 = noise detected in the received character in sci1d. 0 = no noise detected. fe framing error flag fe is set at the same time as rdrf when the receiver detects a logic 0 where the stop bit was expected. this suggests the receiver was not properly aligned to a character frame. to clear fe, read sci1s1 with fe = 1 and then read the sci data register (sci1d). 1 = framing error. 0 = no framing error detected. this does not guarantee the framing is correct. pf parity error flag pf is set at the same time as rdrf when parity is enabled (pe = 1) and the parity bit in the received character does not agree with the expected parity value. to clear pf, read sci1s1 and then read the sci data register (sci1d). 1 = parity error. 0 = no parity error. 11.9.5 sci status register 2 (sci1s2) this register has one read-only status flag. writes have no effect. figure 11-10 sci status register 2 (sci1s2) bit 7 654321 bit 0 read: 0000000 raf write: reset: 00000000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 159 mc9s08rc/rd/re/rg raf receiver active flag raf is set when the sci receiver detects the beginning of a valid start bit, and raf is cleared automatically when the receiver detects an idle line. this status flag can be used to check whether an sci character is being received before instructing the mcu to go to stop mode. 1 = sci receiver active (rxd1 input not idle). 0 = sci receiver idle waiting for a start bit. 11.9.6 sci control register 3 (sci1c3) figure 11-11 sci control register 3 (sci1c3) r8 ninth data bit for receiver when the sci is configured for 9-bit data (m = 1), r8 can be thought of as a ninth receive data bit to the left of the msb of the buffered data in the sci1d register. when reading 9-bit data, read r8 before reading sci1d because reading sci1d completes automatic flag clearing sequences that could allow r8 and sci1d to be overwritten with new data. t8 ninth data bit for transmitter when the sci is configured for 9-bit data (m = 1), t8 may be thought of as a ninth transmit data bit to the left of the msb of the data in the sci1d register. when writing 9-bit data, the entire 9-bit value is transferred to the sci shift register after sci1d is written so t8 should be written (if it needs to change from its previous value) before sci1d is written. if t8 does not need to change in the new value (such as when it is used to generate mark or space parity), it need not be written each time sci1d is written. txdir txd1 pin direction in single-wire mode when the sci is configured for single-wire half-duplex operation (loops = rsrc = 1), this bit determines the direction of data at the txd1 pin. 1 = txd1 pin is an output in single-wire mode. 0 = txd1 pin is an input in single-wire mode. orie overrun interrupt enable this bit enables the overrun flag (or) to generate hardware interrupt requests. 1 = hardware interrupt requested when or = 1. 0 = or interrupts disabled (use polling). bit 7 654321 bit 0 read: r8 t8 txdir 0 orie neie feie peie write: reset: 00000000 = unimplemented or reserved
serial communications interface (sci) module mc9s08rc/rd/re/rg 160 freescale semiconductor neie noise error interrupt enable this bit enables the noise flag (nf) to generate hardware interrupt requests. 1 = hardware interrupt requested when nf = 1. 0 = nf interrupts disabled (use polling). feie framing error interrupt enable this bit enables the framing error flag (fe) to generate hardware interrupt requests. 1 = hardware interrupt requested when fe = 1. 0 = fe interrupts disabled (use polling). peie parity error interrupt enable this bit enables the parity error flag (pf) to generate hardware interrupt requests. 1 = hardware interrupt requested when pf = 1. 0 = pf interrupts disabled (use polling). 11.9.7 sci data register (sci1d) this register is actually two separate registers. reads return the contents of the read-only receive data buffer and writes go to the write-only transmit data buffer. reads and writes of this register are also involved in the automatic flag clearing mechanisms for the sci status flags. figure 11-12 sci data register (sci1d) bit 7 654321 bit 0 read: r7 r6 r5 r4 r3 r2 r1 r0 write: t7 t6 t5 t4 t3 t2 t1 t0 reset: 00000000
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 161 mc9s08rc/rd/re/rg chapter 12 serial peripheral interface (spi) module the spi is only available on the mc9s08rgxx versions of this family of microcontrollers. the spi pins are shared with ptc4-ptc7 port pins. when the spi is enabled these pins are controlled by the spi module. figure 12-1 mc9s08rc/rd/re/rg block diagram highlighting spi block and pins ptd3 ptd4/acmp1 ptd5/acmp1+ ptd6/tpm1ch0 ptc1/kbi2p1 ptc0/kbi2p0 v ss v dd ptb3 ptb2 pta7/kbi1p7 ptb0/txd1 ptb1/rxd1 ptd2/irq ptd1/ reset ptd0/bkgd/ms ptc7/ ss1 ptc6/ spsck1 ptc5/ miso1 ptc4/ mosi1 ptc3/kbi2p3 ptc2/kbi2p2 port a port c port d port b 8-bit keyboard interrupt module (kbi1) serial peripheral interface module (spi1) user flash user ram (rc/rd/re/rg32/60 = 2048 bytes) debug module (dbg) (rc/rd/re/rg60 = 63,364 bytes) hcs08 core notes: 1. port pins are software configurable with pullup device if input port 2. pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . 3. irq pin contains software configurable pullup/pulldown device if irq enabled (irqpe = 1) 4. the reset pin contains integrated pullup device enabled if reset enabled (rstpe = 1) 5. high current drive 6. pins pta[7:0] contain both pullup and pulldown devices. pulldown available when kbi enabled (kbi1pn = 1). notes notes 1, 5 2-channel timer/pwm module (tpm1) pte7 port e ptb5 ptb4 pte6 ptb7/tpm1ch1 module (acmp1) hcs08 system control resets and interrupts modes of operation power management voltage regulator rti analog comparator cop irq lvd internal bus low-power oscillator interface module (sci1) serial communications 7 pta1/kbi1p1 8 pte0 note 1 notes1, 2 note 1 (rc/rd/re/rg32 = 32,768 bytes) (rc/rd/re8/16 = 1024 bytes) (rc/rd/re16 = 16,384 bytes) xtal extal carrier modulator timer module (cmt) 1, 3, 4 4-bit keyboard interrupt module (kbi2) iro note 5 pta0/kbi1p0 (rc/rd/re8 = 8192 bytes) bdc cpu
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 162 freescale semiconductor 12.1 features features of the spi module include: master or slave mode operation full-duplex or single-wire bidirectional option programmable transmit bit rate double-buffered transmit and receive serial clock phase and polarity options slave select output selectable msb-first or lsb-first shifting 12.2 block diagrams this section includes block diagrams showing spi system connections, the internal organization of the spi module, and the spi clock dividers that control the master mode bit rate. 12.2.1 spi system block diagram figure 12-2 shows the spi modules of two mcus connected in a master-slave arrangement. the master device initiates all spi data transfers. during a transfer, the master shifts data out (on the mosi1 pin) to the slave while simultaneously shifting data in (on the miso1 pin) from the slave. the transfer effectively exchanges the data that was in the spi shift registers of the two spi systems. the spsck1 signal is a clock output from the master and an input to the slave. the slave device must be selected by a low level on the slave select input ( ss1 pin). in this system, the master device has configured its ss1 pin as an optional slave select output. figure 12-2 spi system connections 7 6 5 4 3 2 1 0 spi shifter clock generator 7 6 5 4 3 2 1 0 spi shifter ss1 spsck1 miso1 mosi1 ss1 spsck1 miso1 mosi1 master slave
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 163 mc9s08rc/rd/re/rg the most common uses of the spi system include connecting simple shift registers for adding input or output ports or connecting small peripheral devices such as serial a/d or d/a converters. although figure 12-2 shows a system where data is exchanged between two mcus, many practical systems involve simpler connections where data is unidirectionally transferred from the master mcu to a slave or from a slave to the master mcu. 12.2.2 spi module block diagram figure 12-3 is a block diagram of the spi module. the central element of the spi is the spi shift register. data is written to the double-buffered transmitter (write to spi1d) and gets transferred to the spi shift register at the start of a data transfer. after shifting in a byte of data, the data is transferred into the double-buffered receiver where it can be read (read from spi1d). pin multiplexing logic controls connections between mcu pins and the spi module. when the spi is configured as a master, the clock output is routed to the spsck1 pin, the shifter output is routed to mosi1, and the shifter input is routed from the miso1 pin. when the spi is configured as a slave, the spsck1 pin is routed to the clock input of the spi, the shifter output is routed to miso1, and the shifter input is routed from the mosi1 pin. in the external spi system, simply connect all spsck pins to each other, all miso pins together, and all mosi pins together. peripheral devices often use slightly different names for these pins.
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 164 freescale semiconductor figure 12-3 spi module block diagram spi shift register shift clock shift direction rx buffer full tx buffer empty shift out shift in enable spi system clock logic clock generator bus rate clock master/slave mode select mode fault detection master clock slave clock spi interrupt request pin control m s master/ slave mosi1 (momi) miso1 (siso) spsck1 ss1 m s s m modf spe lsbfe mstr sprf sptef sptie spie modfen ssoe spc0 bidiroe spibr tx buffer (write spi1d) rx buffer (read spi1d)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 165 mc9s08rc/rd/re/rg 12.2.3 spi baud rate generation as shown in figure 12-4 , the clock source for the spi baud rate generator is the bus clock. the three prescale bits (sppr2:sppr1:sppr0) choose a prescale divisor of 1, 2, 3, 4, 5, 6, 7, or 8. the three rate select bits (spr2:spr1:spr0) divide the output of the prescaler stage by 2, 4, 8, 16, 32, 64, 128, or 256 to get the internal spi master mode bit-rate clock. figure 12-4 spi baud rate generation 12.3 functional description an spi transfer is initiated by checking for the spi transmit buffer empty flag (sptef = 1) and then writing a byte of data to the spi data register (spi1d) in the master spi device. when the spi shift register is available, this byte of data is moved from the transmit data buffer to the shifter, sptef is set to indicate there is room in the buffer to queue another transmit character if desired, and the spi serial transfer starts. during the spi transfer, data is sampled (read) on the miso1 pin at one spsck edge and shifted, changing the bit value on the mosi1 pin, one-half spsck cycle later. after eight spsck cycles, the data that was in the shift register of the master has been shifted out the mosi1 pin to the slave while eight bits of data were shifted in the miso1 pin into the master? shift register. at the end of this transfer, the received data byte is moved from the shifter into the receive data buffer and sprf is set to indicate the data can be read by reading spi1d. if another byte of data is waiting in the transmit buffer at the end of a transfer, it is moved into the shifter, sptef is set, and a new transfer is started. normally, spi data is transferred most significant bit (msb) first. if the least significant bit first enable (lsbfe) bit is set, spi data is shifted lsb first. when the spi is configured as a slave, its ss1 pin must be driven low before a transfer starts and ss1 must stay low throughout the transfer. if a clock format where cpha = 0 is selected, ss1 must be driven to a logic 1 between successive transfers. if cpha = 1, ss1 may remain low between successive transfers. see 12.3.1 spi clock formats for more details. because the transmitter and receiver are double buffered, a second byte, in addition to the byte currently being shifted out, can be queued into the transmit data buffer, and a previously received character can be in the receive data buffer while a new character is being shifted in. the sptef flag indicates when the transmit buffer has room for a new character. the sprf flag indicates when a received character is available in the receive data buffer. the received character must be read out of the receive buffer (read spi1d) before the next transfer is finished or a receive overrun error results. divide by 2, 4, 8, 16, 32, 64, 128, or 256 divide by 1, 2, 3, 4, 5, 6, 7, or 8 prescaler clock rate divider sppr2:sppr1:sppr0 spr2:spr1:spr0 bus clock master spi bit rate
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 166 freescale semiconductor in the case of a receive overrun, the new data is lost because the receive buffer still held the previous character and was not ready to accept the new data. there is no indication for such an overrun condition so the application system designer must ensure that previous data has been read from the receive buffer before a new transfer is initiated. 12.3.1 spi clock formats to accommodate a wide variety of synchronous serial peripherals from different manufacturers, the spi system has a clock polarity (cpol) bit and a clock phase (cpha) control bit to select one of four clock formats for data transfers. cpol selectively inserts an inverter in series with the clock. cpha chooses between two different clock phase relationships between the clock and data. figure 12-5 shows the clock formats when cpha = 1. at the top of the figure, the eight bit times are shown for reference with bit 1 starting at the first spsck edge and bit 8 ending one-half spsck cycle after the sixteenth spsck edge. the msb first and lsb first lines show the order of spi data bits depending on the setting in lsbfe. both variations of spsck polarity are shown, but only one of these waveforms applies for a specific transfer, depending on the value in cpol. the sample in waveform applies to the mosi input of a slave or the miso input of a master. the mosi waveform applies to the mosi output pin from a master and the miso waveform applies to the miso output from a slave. the ss out waveform applies to the slave select output from a master (provided modfen and ssoe = 1). the master ss output goes to active low one-half spsck cycle before the start of the transfer and goes back high at the end of the eighth bit time of the transfer. the ss in waveform applies to the slave select input of a slave.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 167 mc9s08rc/rd/re/rg figure 12-5 spi clock formats (cpha = 1) when cpha = 1, the slave begins to drive its miso output when ss1 goes to active low, but the data is not defined until the first spsck edge. the first spsck edge shifts the first bit of data from the shifter onto the mosi output of the master and the miso output of the slave. the next spsck edge causes both the master and the slave to sample the data bit values on their miso and mosi inputs, respectively. at the third spsck edge, the spi shifter shifts one bit position which shifts in the bit value that was just sampled, and shifts the second data bit value out the other end of the shifter to the mosi and miso outputs of the master and slave, respectively. when chpa = 1, the slave? ss input is not required to go to its inactive high level between transfers. figure 12-6 shows the clock formats when cpha = 0. at the top of the figure, the eight bit times are shown for reference with bit 1 starting as the slave is selected ( ss in goes low), and bit 8 ends at the last spsck edge. the msb first and lsb first lines show the order of spi data bits depending on the setting in lsbfe. both variations of spsck polarity are shown, but only one of these waveforms applies for a specific transfer, depending on the value in cpol. the sample in waveform applies to the mosi input of a slave or the miso input of a master. the mosi waveform applies to the mosi output pin from a master and the miso waveform applies to the miso output from a slave. the ss out waveform applies to the slave select output from a master (provided modfen and ssoe = 1). the master ss output goes to active low at the start of the first bit time of the transfer and goes back high one-half spsck cycle after the end of the eighth bit time of the transfer. the ss in waveform applies to the slave select input of a slave. bit time # (reference) msb first lsb first spsck (cpol = 0) spsck (cpol = 1) sample in (miso or mosi) mosi (master out) miso (slave out) ss out (master) ss in (slave) bit 7 bit 0 bit 6 bit 1 bit 2 bit 5 bit 1 bit 6 bit 0 bit 7 12 67 8 ... ... ...
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 168 freescale semiconductor figure 12-6 spi clock formats (cpha = 0) when cpha = 0, the slave begins to drive its miso output with the first data bit value (msb or lsb depending on lsbfe) when ss1 goes to active low. the first spsck edge causes both the master and the slave to sample the data bit values on their miso and mosi inputs, respectively. at the second spsck edge, the spi shifter shifts one bit position which shifts in the bit value that was just sampled and shifts the second data bit value out the other end of the shifter to the mosi and miso outputs of the master and slave, respectively. when cpha = 0, the slave? ss input must go to its inactive high level between transfers. 12.3.2 spi pin controls the spi optionally shares four port pins. the function of these pins depends on the settings of spi control bits. when the spi is disabled (spe = 0), these four pins revert to being general-purpose port i/o pins that are not controlled by the spi. 12.3.2.1 spsck1 ?spi serial clock when the spi is enabled as a slave, this pin is the serial clock input. when the spi is enabled as a master, this pin is the serial clock output. bit time # (reference) msb first lsb first spsck (cpol = 0) spsck (cpol = 1) sample in (miso or mosi) mosi (master out) miso (slave out) ss out (master) ss in (slave) bit 7 bit 0 bit 6 bit 1 bit 2 bit 5 bit 1 bit 6 bit 0 bit 7 12 67 8 ... ... ...
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 169 mc9s08rc/rd/re/rg 12.3.2.2 mosi1 ?master data out, slave data in when the spi is enabled as a master and spi pin control zero (spc0) is 0 (not bidirectional mode), this pin is the serial data output. when the spi is enabled as a slave and spc0 = 0, this pin is the serial data input. if spc0 = 1 to select single-wire bidirectional mode, and master mode is selected, this pin becomes the bidirectional data i/o pin (momi). also, the bidirectional mode output enable bit determines whether the pin acts as an input (bidiroe = 0) or an output (bidiroe = 1). if spc0 = 1 and slave mode is selected, this pin is not used by the spi and reverts to being a general-purpose port i/o pin. 12.3.2.3 miso1 ?master data in, slave data out when the spi is enabled as a master and spi pin control zero (spc0) is 0 (not bidirectional mode), this pin is the serial data input. when the spi is enabled as a slave and spc0 = 0, this pin is the serial data output. if spc0 = 1 to select single-wire bidirectional mode, and slave mode is selected, this pin becomes the bidirectional data i/o pin (siso) and the bidirectional mode output enable bit determines whether the pin acts as an input (bidiroe = 0) or an output (bidiroe = 1). if spc0 = 1 and master mode is selected, this pin is not used by the spi and reverts to being a general-purpose port i/o pin. 12.3.2.4 ss1 ?slave select when the spi is enabled as a slave, this pin is the low-true slave select input. when the spi is enabled as a master and mode fault enable is off (modfen = 0), this pin is not used by the spi and reverts to being a general-purpose port i/o pin. when the spi is enabled as a master and modfen = 1, the slave select output enable bit determines whether this pin acts as the mode fault input (ssoe = 0) or as the slave select output (ssoe = 1). 12.3.3 spi interrupts there are three flag bits, two interrupt mask bits, and one interrupt vector associated with the spi system. the spi interrupt enable mask (spie) enables interrupts from the spi receiver full flag (sprf) and mode fault flag (modf). the spi transmit interrupt enable mask (sptie) enables interrupts from the spi transmit buffer empty flag (sptef). when one of the flag bits is set, and the associated interrupt mask bit is set, a hardware interrupt request is sent to the cpu. if the interrupt mask bits are cleared, software can poll the associated flag bits instead of using interrupts. the spi interrupt service routine (isr) should check the flag bits to determine what event caused the interrupt. the service routine should also clear the flag bit(s) before returning from the isr (usually near the beginning of the isr). 12.3.4 mode fault detection a mode fault occurs and the mode fault flag (modf) becomes set when a master spi device detects an error on the ss1 pin (provided the ss1 pin is configured as the mode fault input signal). the ss1 pin is configured to be the mode fault input signal when mstr = 1, mode fault enable is set (modfen = 1), and slave select output enable is clear (ssoe = 0). the mode fault detection feature can be used in a system where more than one spi device might become a master at the same time. the error is detected when a master? ss1 pin is low, indicating that some other spi device is trying to address this master as if it were a slave. this could indicate a harmful output driver conflict, so the mode fault logic is designed to disable all spi output drivers when such an error is detected.
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 170 freescale semiconductor when a mode fault is detected, modf is set and mstr is cleared to change the spi configuration back to slave mode. the output drivers on the spsck1, mosi1, and miso1 (if not bidirectional mode) are disabled. modf is cleared by reading it while it is set, then writing to the spi control register 1 (spi1c1). user software should verify the error condition has been corrected before changing the spi back to master mode. 12.4 spi registers and control bits the spi has five 8-bit registers to select spi options, control baud rate, report spi status, and for transmit/receive data. refer to the direct-page register summary in the memory section of this data sheet for the absolute address assignments for all spi registers. this section refers to registers and control bits only by their names, and a freescale-provided equate or header file is used to translate these names into the appropriate absolute addresses. 12.4.1 spi control register 1 (spi1c1) this read/write register includes the spi enable control, interrupt enables, and configuration options. figure 12-7 spi control register 1 (spi1c1) spie spi interrupt enable (for sprf and modf) this is the interrupt enable for spi receive buffer full (sprf) and mode fault (modf) events. 1 = when sprf or modf is 1, request a hardware interrupt. 0 = interrupts from sprf and modf inhibited (use polling). spe spi system enable disabling the spi halts any transfer that is in progress, clears data buffers, and initializes internal state machines. sprf is cleared and sptef is set to indicate the spi transmit data buffer is empty. 1 = spi system enabled. 0 = spi system inactive. bit 7 654321 bit 0 read: spie spe sptie mstr cpol cpha ssoe lsbfe write: reset: 00000100
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 171 mc9s08rc/rd/re/rg sptie spi transmit interrupt enable this is the interrupt enable bit for spi transmit buffer empty (sptef). 1 = when sptef is 1, hardware interrupt requested. 0 = interrupts from sptef inhibited (use polling). mstr master/slave mode select 1 = spi module configured as a master spi device. 0 = spi module configured as a slave spi device. cpol clock polarity this bit effectively places an inverter in series with the clock signal from a master spi or to a slave spi device. refer to 12.3.1 spi clock formats for more details. 1 = active-low spi clock (idles high). 0 = active-high spi clock (idles low). cpha clock phase this bit selects one of two clock formats for different kinds of synchronous serial peripheral devices. refer to 12.3.1 spi clock formats for more details. 1 = first edge on spsck occurs at the start of the first cycle of an 8-cycle data transfer. 0 = first edge on spsck occurs at the middle of the first cycle of an 8-cycle data transfer. ssoe slave select output enable this bit is used in combination with the mode fault enable (modfen) bit in spcr2 and the master/slave (mstr) control bit to determine the function of the ss1 pin as shown in table 12-1 . lsbfe lsb first (shifter direction) 1 = spi serial data transfers start with least significant bit. 0 = spi serial data transfers start with most significant bit. table 12-1 ss1 pin function modfen ssoe master mode slave mode 0 0 general-purpose i/o (not spi) slave select input 0 1 general-purpose i/o (not spi) slave select input 10 ss input for mode fault slave select input 1 1 automatic ss output slave select input
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 172 freescale semiconductor 12.4.2 spi control register 2 (spi1c2) this read/write register is used to control optional features of the spi system. bits 7, 6, 5, and 2 are not implemented and always read 0. figure 12-8 spi control register 2 (spi1c2) modfen master mode-fault function enable when the spi is configured for slave mode, this bit has no meaning or effect. (the ss1 pin is the slave select input.) in master mode, this bit determines how the ss1 pin is used (refer to table 12-1 for more details). 1 = mode fault function enabled, master ss1 pin acts as the mode fault input or the slave select output. 0 = mode fault function disabled, master ss1 pin reverts to general-purpose i/o not controlled by spi. bidiroe bidirectional mode output enable when bidirectional mode is enabled by spi pin control 0 (spc0) = 1, bidiroe determines whether the spi data output driver is enabled to the single bidirectional spi i/o pin. depending on whether the spi is configured as a master or a slave, it uses either the mosi1 (momi) or miso1 (siso) pin, respectively, as the single spi data i/o pin. when spc0 = 0, bidiroe has no meaning or effect. 1 = spi i/o pin enabled as an output. 0 = output driver disabled so spi data i/o pin acts as an input. spiswai spi stop in wait mode 1 = spi clocks stop when the mcu enters wait mode. 0 = spi clocks continue to operate in wait mode. spc0 spi pin control 0 the spc0 bit chooses single-wire bidirectional mode. if mstr = 0 (slave mode), the spi uses the miso1 (siso) pin for bidirectional spi data transfers. if mstr = 1 (master mode), the spi uses the mosi1 (momi) pin for bidirectional spi data transfers. when spc0 = 1, bidiroe is used to enable or disable the output driver for the single bidirectional spi i/o pin. 1 = spi configured for single-wire bidirectional operation. 0 = spi uses separate pins for data input and data output. bit 7 6 54321 bit 0 read: 0 0 0 modfen bidiroe 0 spiswai spc0 write: reset: 0 0 000000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 173 mc9s08rc/rd/re/rg 12.4.3 spi baud rate register (spi1br) this register is used to set the prescaler and bit rate divisor for an spi master. this register may be read or written at any time. figure 12-9 spi baud rate register (spi1br) sppr2:sppr1:sppr0 spi baud rate prescale divisor this 3-bit field selects one of eight divisors for the spi baud rate prescaler as shown in table 12-2 . the input to this prescaler is the bus rate clock (busclk). the output of this prescaler drives the input of the spi baud rate divider (see figure 12-4 ). bit 7 654321 bit 0 read: 0 sppr2 sppr1 sppr0 0 spr2 spr1 spr0 write: reset: 00000000 = unimplemented or reserved table 12-2 spi baud rate prescaler divisor sppr2:sppr1:sppr0 prescaler divisor 0:0:0 1 0:0:1 2 0:1:0 3 0:1:1 4 1:0:0 5 1:0:1 6 1:1:0 7 1:1:1 8
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 174 freescale semiconductor spr2:spr1:spr0 spi baud rate divisor this 3-bit field selects one of eight divisors for the spi baud rate divider as shown in table 12-3 . the input to this divider comes from the spi baud rate prescaler (see figure 12-4 ). the output of this divider is the spi bit rate clock for master mode. 12.4.4 spi status register (spi1s) this register has three read-only status bits. bits 6, 3, 2, 1, and 0 are not implemented and always read 0s. writes have no meaning or effect. figure 12-10 spi status register (spi1s) sprf spi read buffer full flag sprf is set at the completion of an spi transfer to indicate that received data may be read from the spi data register (spi1d). sprf is cleared by reading sprf while it is set, then reading the spi data register. 1 = data available in the receive data buffer. 0 = no data available in the receive data buffer. table 12-3 spi baud rate divisor spr2:spr1:spr0 rate divisor 0:0:0 2 0:0:1 4 0:1:0 8 0:1:1 16 1:0:0 32 1:0:1 64 1:1:0 128 1:1:1 256 bit 7 654321 bit 0 read: sprf 0 sptef modf 0000 write: reset: 00100000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 175 mc9s08rc/rd/re/rg sptef spi transmit buffer empty flag this bit is set when there is room in the transmit data buffer. it is cleared by reading spi1s with sptef set, followed by writing a data value to the transmit buffer at spi1d. spi1s must be read with sptef = 1 before writing data to spi1d or the spi1d write will be ignored. sptef generates an sptef cpu interrupt request if the sptie bit in the spi1c1 is also set. sptef is automatically set when a data byte transfers from the transmit buffer into the transmit shift register. for an idle spi (no data in the transmit buffer or the shift register and no transfer in progress), data written to spi1d is transferred to the shifter almost immediately so sptef is set within two bus cycles allowing a second 8-bit data value to be queued into the transmit buffer. after completion of the transfer of the value in the shift register, the queued value from the transmit buffer will automatically move to the shifter and sptef will be set to indicate there is room for new data in the transmit buffer. if no new data is waiting in the transmit buffer, sptef simply remains set and no data moves from the buffer to the shifter. 1 = spi transmit buffer empty. 0 = spi transmit buffer not empty. modf master mode fault flag modf is set if the spi is configured as a master and the slave select input goes low, indicating some other spi device is also configured as a master. the ss1 pin acts as a mode fault error input only when mstr = 1, modfen = 1, and ssoe = 0; otherwise, modf will never be set. modf is cleared by reading modf while it is 1, then writing to spi control register 1 (spi1c1). 1 = mode fault error detected. 0 = no mode fault error. 12.4.5 spi data register (spi1d) figure 12-11 spi data register (spi1d) reads of this register return the data read from the receive data buffer. writes to this register write data to the transmit data buffer. when the spi is configured as a master, writing data to the transmit data buffer initiates an spi transfer. data should not be written to the transmit data buffer unless the spi transmit buffer empty flag (sptef) is set, indicating there is room in the transmit buffer to queue a new transmit byte. data may be read from spi1d any time after sprf is set and before another transfer is finished. failure to read the data out of the receive data buffer before a new transfer ends causes a receive overrun condition and the data from the new transfer is lost. bit 7 654321 bit 0 read: bit 7 654321 bit 0 write: reset: 00000000
serial peripheral interface (spi) module mc9s08rc/rd/re/rg 176 freescale semiconductor
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 177 mc9s08rc/rd/re/rg chapter 13 analog comparator (acmp) module the 32- and 44-pin lqfp packages of the mc9s08rcxx, mc9s08rexx, and mc9s08rgxx devices include an analog comparator. this comparator has two inputs or can optionally use an internal bandgap reference. the comparator inputs are shared with ptd4 and ptd5 port i/o pins. figure 13-1 mc9s08rc/rd/re/rg block diagram highlighting acmp block and pins ptd3 ptd4/ acmp1 ptd5/ acmp1+ ptd6/tpm1ch0 ptc1/kbi2p1 ptc0/kbi2p0 v ss v dd ptb3 ptb2 pta7/kbi1p7 ptb0/txd1 ptb1/rxd1 ptd2/irq ptd1/ reset ptd0/bkgd/ms ptc7/ ss1 ptc6/spsck1 ptc5/miso1 ptc4/mosi1 ptc3/kbi2p3 ptc2/kbi2p2 port a port c port d port b 8-bit keyboard interrupt module (kbi1) serial peripheral interface module (spi1) user flash user ram (rc/rd/re/rg32/60 = 2048 bytes) debug module (dbg) (rc/rd/re/rg60 = 63,364 bytes) hcs08 core cpu bdc int bkp notes: 1. port pins are software configurable with pullup device if input port 2. pta0 does not have a clamp diode to v dd . pta0 should not be driven above v dd . 3. irq pin contains software configurable pullup/pulldown device if irq enabled (irqpe = 1) 4. the reset pin contains integrated pullup device enabled if reset enabled (rstpe = 1) 5. high current drive 6. pins pta[7:0] contain both pullup and pulldown devices. pulldown available when kbi enabled (kbipn = 1). notes notes 1, 5 2-channel timer/pwm module (tpm1) pte7 port e ptb5 ptb4 pte6 ptb7/tpm1ch1 module (acmp1) hcs08 system control resets and interrupts modes of operation power management voltage regulator rti analog comparator cop irq lvd internal bus low-power oscillator interface module (sci1) serial communications 7 pta1/kbi1p1 8 pte0 note 1 notes1, 2 note 1 (rc/rd/re/rg32 = 32,768 bytes) (rc/rd/re8/16 = 1024 bytes) (rc/rd/re16 = 16,384 bytes) xtal extal carrier modulator timer module (cmt) 1, 3, 4 4-bit keyboard interrupt module (kbi2) iro note 5 pta0/kbi1p0 (rc/rd/re8 = 8192 bytes)
analog comparator (acmp) module mc9s08rc/rd/re/rg 178 freescale semiconductor 13.1 features the acmp has the following features: full rail-to-rail supply operation. less than 40 mv of input offset. selectable interrupt on rising edge, falling edge, or either rising or falling edge of comparator output. option to compare to fixed internal bandgap reference voltage. 13.2 block diagram the block diagram for the analog comparator module is shown below. figure 13-2 analog comparator module block diagram 13.3 pin description the acmp has two analog input pins: acmp1?and acmp1+. each of these pins can accept an input voltage that varies across the full operating voltage range of the mcu. when the acmp1+ is configured to use the internal bandgap reference, acmp1+ is available to be as general-purpose i/o. as shown in the block diagram, the acmp1+ pin is connected to the comparator non-inverting input if acbgs is equal to logic 0, and the acmp1?pin is connected to the inverting input of the comparator. + interrupt control ac irq internal reference acbgs internal bus status & control register acmod1 acmod0 set acf acpe acf acie acmp1+ acmp1
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 179 mc9s08rc/rd/re/rg 13.4 functional description the analog comparator can be used to compare two analog input voltages applied to acmp1?and acmp1+; or it can be used to compare an analog input voltage applied to acmp1?with an internal bandgap reference voltage. the acbgs bit is used to select the mode of operation. the comparator output is high when the non-inverting input is greater than the inverting input, and is low when the non-inverting input is less than the inverting input. the acmod0 and acmod1 bits are used to select the condition that will cause the acf bit to be set. the acf bit can be set on a rising edge of the comparator output, a falling edge of the comparator output, or either a rising or a falling edge. the comparator output can be read directly through the aco bit. 13.4.1 interrupts the acmp module is capable of generating an interrupt on a compare event. the interrupt request is asserted when both the acie bit and the acf bit are set. the interrupt is deasserted by clearing either the acie bit or the acf bit. the acie bit is cleared by writing a 0 and the acf bit is cleared by writing a 1. 13.4.2 wait mode operation during wait mode the acmp, if enabled, will continue to operate normally. also, if enabled, the interrupt can wake up the mcu. 13.4.3 stop mode operation during stop mode, clocks to the acmp module are halted. the acmp comparator circuit will enter a low power state. no compare operation will occur while in stop mode. in stop1 and stop2 modes, the acmp module will be in its reset state when the mcu recovers from the stop condition and must be re-initialized. in stop3 mode, control and status register information is maintained and upon recovery normal acmp function is available to the user. 13.4.4 background mode operation when the microcontroller is in active background mode, the acmp will continue to operate normally.
analog comparator (acmp) module mc9s08rc/rd/re/rg 180 freescale semiconductor 13.5 acmp status and control register (acmp1sc) acme analog comparator module enable the acme bit enables the analog comparator module. when the module is not enabled, it remains in a low-power state. 1 = analog comparator enabled 0 = analog comparator disabled acbgs analog comparator bandgap select the acbgs bit is used to select the internal bandgap as the comparator reference. 1 = internal bandgap reference selected as comparator non-inverting input 0 = external pin acmp1+ selected as comparator non-inverting input acf analog comparator flag the acf bit is set when a compare event occurs. compare events are defined by the acmod0 and acmod1 bits. the acf bit is cleared by writing a 1 to the bit. 1 = compare event has occurred. 0 = compare event has not occurred. acie analog comparator interrupt enable the acie bit enables the interrupt from the acmp. when this bit is set, an interrupt will be asserted when the acf bit is set. 1 = interrupt enabled 0 = interrupt disabled aco analog comparator output reading the aco bit will return the current value of the analog comparator output. the register bit is reset to 0 and will read as 0 when the analog comparator module is disabled (acme = 0). acmod1:acmod0 analog comparator modes the acmod1 and acmod0 bits select the flag setting mode that controls the type of compare event that sets the acf bit. bit 7 654321 bit 0 read: acme acbgs acf acie aco 0 acmod1 acmod0 write: reset: 00000000 = unimplemented figure 13-3 acmp status and control register (acmp1sc)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 181 mc9s08rc/rd/re/rg table 13-1 analog comparator modes acmod1:acmod0 flag setting mode 00 or 10 comparator output falling edge 01 comparator output rising edge 11 comparator output either rising or falling edge
analog comparator (acmp) module mc9s08rc/rd/re/rg 182 freescale semiconductor
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 183 mc9s08rc/rd/re/rg chapter 14 development support 14.1 introduction development support systems in the hcs08 include the background debug controller (bdc) and the on-chip debug module (dbg). the bdc provides a single-wire debug interface to the target mcu that provides a convenient interface for programming the on-chip flash and other nonvolatile memories. the bdc is also the primary debug interface for development and allows non-intrusive access to memory data and traditional debug features such as cpu register modify, breakpoints, and single instruction trace commands. in the hcs08 family, address and data bus signals are not available on external pins (not even in test modes). debug is done through commands fed into the target mcu via the single-wire background debug interface. the debug module provides a means to selectively trigger and capture bus information so an external development system can reconstruct what happened inside the mcu on a cycle-by-cycle basis without having external access to the address and data signals. the alternate bdc clock source for the mc9s08rc/rd/re/rg devices is the oscillator output (oscout).
development support mc9s08rc/rd/re/rg 184 freescale semiconductor 14.2 features features of the background debug controller (bdc) include: single pin for mode selection and background communications bdc registers are not located in the memory map sync command to determine target communications rate non-intrusive commands for memory access active background mode commands for cpu register access go and trace1 commands background command can wake cpu from stop or wait modes one hardware address breakpoint built into bdc oscillator runs in stop mode, if bdc enabled cop watchdog disabled while in active background mode features of the debug module (dbg) include: two trigger comparators: two address + read/write (r/w) or one full address + data + r/w flexible 8-word by 16-bit fifo (first-in, first-out) buffer for capture information: change-of-flow addresses or event-only data two types of breakpoints: tag breakpoints for instruction opcodes force breakpoints for any address access nine trigger modes: a-only a or b a then b a and b data (full mode) a and not b data (full mode) event-only b (store data) a then event-only b (store data) inside range (a address b) outside range (address < a or address > b)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 185 mc9s08rc/rd/re/rg 14.3 background debug controller (bdc) all mcus in the hcs08 family contain a single-wire background debug interface that supports in-circuit programming of on-chip nonvolatile memory and sophisticated non-intrusive debug capabilities. unlike debug interfaces on earlier 8-bit mcus, this system does not interfere with normal application resources. it does not use any user memory or locations in the memory map and does not share any on-chip peripherals. bdc commands are divided into two groups: active background mode commands require that the target mcu is in active background mode (the user program is not running). active background mode commands allow the cpu registers to be read or written, and allow the user to trace one user instruction at a time, or go to the user program from active background mode. non-intrusive commands can be executed at any time even while the user? program is running. non-intrusive commands allow a user to read or write mcu memory locations or access status and control registers within the background debug controller. typically, a relatively simple interface pod is used to translate commands from a host computer into commands for the custom serial interface to the single-wire background debug system. depending on the development tool vendor, this interface pod may use a standard rs-232 serial port, a parallel printer port, or some other type of communications such as a universal serial bus (usb) to communicate between the host pc and the pod. the pod typically connects to the target system with ground, the bkgd pin, reset, and sometimes v dd . an open-drain connection to reset allows the host to force a target system reset, which is useful to regain control of a lost target system or to control startup of a target system before the on-chip nonvolatile memory has been programmed. sometimes v dd can be used to allow the pod to use power from the target system to avoid the need for a separate power supply. however, if the pod is powered separately, it can be connected to a running target system without forcing a target system reset or otherwise disturbing the running application program. figure 14-1 bdm tool connector 14.3.1 bkgd pin description bkgd is the single-wire background debug interface pin. the primary function of this pin is for bidirectional serial communication of active background mode commands and data. during reset, this pin is used to select between starting in active background mode or starting the user? application program. this pin is also used to request a timed sync response pulse to allow a host development tool to determine the correct clock frequency for background debug serial communications. bdc serial communications use a custom serial protocol first introduced on the m68hc12 family of microcontrollers. this protocol assumes the host knows the communication clock rate that is determined 2 4 6 no connect 5 no connect 3 1 reset bkgd gnd v dd
development support mc9s08rc/rd/re/rg 186 freescale semiconductor by the target bdc clock rate. all communication is initiated and controlled by the host that drives a high-to-low edge to signal the beginning of each bit time. commands and data are sent most significant bit first (msb first). for a detailed description of the communications protocol, refer to 14.3.2 communication details . if a host is attempting to communicate with a target mcu that has an unknown bdc clock rate, a sync command may be sent to the target mcu to request a timed sync response signal from which the host can determine the correct communication speed. bkgd is a pseudo-open-drain pin and there is an on-chip pullup so no external pullup resistor is required. unlike typical open-drain pins, the external rc time constant on this pin, which is influenced by external capacitance, plays almost no role in signal rise time. the custom protocol provides for brief, actively driven speedup pulses to force rapid rise times on this pin without risking harmful drive level conflicts. refer to 14.3.2 communication details for more detail. when no debugger pod is connected to the 6-pin bdm interface connector, the internal pullup on bkgd chooses normal operating mode. when a development system is connected, it can pull both bkgd and reset low, release reset to select active background mode rather than normal operating mode, then release bkgd. it is not necessary to reset the target mcu to communicate with it through the background debug interface. 14.3.2 communication details the bdc serial interface requires the external controller to generate a falling edge on the bkgd pin to indicate the start of each bit time. the external controller provides this falling edge whether data is transmitted or received. bkgd is a pseudo-open-drain pin that can be driven either by an external controller or by the mcu. data is transferred msb first at 16 bdc clock cycles per bit (nominal speed). the interface times out if 512 bdc clock cycles occur between falling edges from the host. any bdc command that was in progress when this timeout occurs is aborted without affecting the memory or operating mode of the target mcu system. the custom serial protocol requires the debug pod to know the target bdc communication clock speed. the clock switch (clksw) control bit in the bdc status and control register allows the user to select the bdc clock source. the bdc clock source can either be the bus or the alternate bdc clock source. the bkgd pin can receive a high or low level or transmit a high or low level. the following diagrams show timing for each of these cases. interface timing is synchronous to clocks in the target bdc, but asynchronous to the external host. the internal bdc clock signal is shown for reference in counting cycles.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 187 mc9s08rc/rd/re/rg figure 14-2 shows an external host transmitting a logic 1 or 0 to the bkgd pin of a target hcs08 mcu. the host is asynchronous to the target so there is a 0-to-1 cycle delay from the host-generated falling edge to where the target perceives the beginning of the bit time. ten target bdc clock cycles later, the target senses the bit level on the bkgd pin. typically, the host actively drives the pseudo-open-drain bkgd pin during host-to-target transmissions to speed up rising edges. because the target does not drive the bkgd pin during the host-to-target transmission period, there is no need to treat the line as an open-drain signal during this period. figure 14-2 bdc host-to-target serial bit timing earliest start target senses bit level 10 cycles synchronization uncertainty bdc clock (target mcu) host transmit 1 host transmit 0 perceived start of bit time of next bit
development support mc9s08rc/rd/re/rg 188 freescale semiconductor figure 14-3 shows the host receiving a logic 1 from the target hcs08 mcu. because the host is asynchronous to the target mcu, there is a 0-to-1 cycle delay from the host-generated falling edge on bkgd to the perceived start of the bit time in the target mcu. the host holds the bkgd pin low long enough for the target to recognize it (at least two target bdc cycles). the host must release the low drive before the target mcu drives a brief active-high speedup pulse seven cycles after the perceived start of the bit time. the host should sample the bit level about 10 cycles after it started the bit time. figure 14-3 bdc target-to-host serial bit timing (logic 1) host samples bkgd pin 10 cycles bdc clock (target mcu) host drive to bkgd pin target mcu speedup pulse perceived start of bit time high-impedance high-impedance high-impedance bkgd pin r-c rise 10 cycles earliest start of next bit
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 189 mc9s08rc/rd/re/rg figure 14-4 shows the host receiving a logic 0 from the target hcs08 mcu. because the host is asynchronous to the target mcu, there is a 0-to-1 cycle delay from the host-generated falling edge on bkgd to the start of the bit time as perceived by the target mcu. the host initiates the bit time but the target hcs08 finishes it. because the target wants the host to receive a logic 0, it drives the bkgd pin low for 13 bdc clock cycles, then briefly drives it high to speed up the rising edge. the host samples the bit level about 10 cycles after starting the bit time. figure 14-4 bdm target-to-host serial bit timing (logic 0) 10 cycles bdc clock (target mcu) host drive to bkgd pin target mcu drive and perceived start of bit time high-impedance bkgd pin 10 cycles speed-up pulse speedup pulse earliest start of next bit host samples bkgd pin
development support mc9s08rc/rd/re/rg 190 freescale semiconductor 14.3.3 bdc commands bdc commands are sent serially from a host computer to the bkgd pin of the target hcs08 mcu. all commands and data are sent msb-first using a custom bdc communications protocol. active background mode commands require that the target mcu is currently in the active background mode while non-intrusive commands may be issued at any time whether the target mcu is in active background mode or running a user application program. table 14-1 shows all hcs08 bdc commands, a shorthand description of their coding structure, and the meaning of each command. coding structure nomenclature this nomenclature is used in table 14-1 to describe the coding structure of the bdc commands. commands begin with an 8-bit hexadecimal command code in the host-to-target direction (most signi?ant bit ?st) / = separates parts of the command d = delay 16 target bdc clock cycles aaaa = a 16-bit address in the host-to-target direction rd = 8 bits of read data in the target-to-host direction wd = 8 bits of write data in the host-to-target direction rd16 = 16 bits of read data in the target-to-host direction wd16 = 16 bits of write data in the host-to-target direction ss = the contents of bdcscr in the target-to-host direction (status) cc = 8 bits of write data for bdcscr in the host-to-target direction (control) rbkp = 16 bits of read data in the target-to-host direction (from bdcbkpt breakpoint register) wbkp = 16 bits of write data in the host-to-target direction (for bdcbkpt breakpoint register)
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 191 mc9s08rc/rd/re/rg table 14-1 bdc command summary command mnemonic active bdm/ non-intrusive coding structure description sync non-intrusive n/a (1) notes : 1. the sync command is a special operation that does not have a command code. request a timed reference pulse to determine target bdc communication speed ack_enable non-intrusive d5/d enable acknowledge protocol. refer to freescale document hcs08rmv1/d. ack_disable non-intrusive d6/d disable acknowledge protocol. refer to freescale document hcs08rmv1/d. background non-intrusive 90/d enter active background mode if enabled (ignore if enbdm bit equals 0) read_status non-intrusive e4/ss read bdc status from bdcscr write_control non-intrusive c4/cc write bdc controls in bdcscr read_byte non-intrusive e0/aaaa/d/rd read a byte from target memory read_byte_ws non-intrusive e1/aaaa/d/ss/rd read a byte and report status read_last non-intrusive e8/ss/rd re-read byte from address just read and report status write_byte non-intrusive c0/aaaa/wd/d write a byte to target memory write_byte_ws non-intrusive c1/aaaa/wd/d/ss write a byte and report status read_bkpt non-intrusive e2/rbkp read bdcbkpt breakpoint register write_bkpt non-intrusive c2/wbkp write bdcbkpt breakpoint register go active bdm 08/d go to execute the user application program starting at the address currently in the pc trace1 active bdm 10/d trace 1 user instruction at the address in the pc, then return to active background mode taggo active bdm 18/d same as go but enable external tagging (hcs08 devices have no external tagging pin) read_a active bdm 68/d/rd read accumulator (a) read_ccr active bdm 69/d/rd read condition code register (ccr) read_pc active bdm 6b/d/rd16 read program counter (pc) read_hx active bdm 6c/d/rd16 read h and x register pair (h:x) read_sp active bdm 6f/d/rd16 read stack pointer (sp) read_next active bdm 70/d/rd increment h:x by one then read memory byte located at h:x read_next_ws active bdm 71/d/ss/rd increment h:x by one then read memory byte located at h:x. report status and data. write_a active bdm 48/wd/d write accumulator (a) write_ccr active bdm 49/wd/d write condition code register (ccr) write_pc active bdm 4b/wd16/d write program counter (pc) write_hx active bdm 4c/wd16/d write h and x register pair (h:x) write_sp active bdm 4f/wd16/d write stack pointer (sp) write_next active bdm 50/wd/d increment h:x by one, then write memory byte located at h:x write_next_ws active bdm 51/wd/d/ss increment h:x by one, then write memory byte located at h:x. also report status.
development support mc9s08rc/rd/re/rg 192 freescale semiconductor the sync command is unlike other bdc commands because the host does not necessarily know the correct communications speed to use for bdc communications until after it has analyzed the response to the sync command. to issue a sync command, the host: drives the bkgd pin low for at least 128 cycles of the slowest possible bdc clock (the slowest clock is normally the reference oscillator/64 or the self-clocked rate/64.) drives bkgd high for a brief speedup pulse to get a fast rise time (this speedup pulse is typically one cycle of the fastest clock in the system.) removes all drive to the bkgd pin so it reverts to high impedance monitors the bkgd pin for the sync response pulse the target, upon detecting the sync request from the host (which is a much longer low time than would ever occur during normal bdc communications): waits for bkgd to return to a logic high delays 16 cycles to allow the host to stop driving the high speedup pulse drives bkgd low for 128 bdc clock cycles drives a 1-cycle high speedup pulse to force a fast rise time on bkgd removes all drive to the bkgd pin so it reverts to high impedance the host measures the low time of this 128-cycle sync response pulse and determines the correct speed for subsequent bdc communications. typically, the host can determine the correct communication speed within a few percent of the actual target speed and the communication protocol can easily tolerate speed errors of several percent. 14.3.4 bdc hardware breakpoint the bdc includes one relatively simple hardware breakpoint that compares the cpu address bus to a 16-bit match value in the bdcbkpt register. this breakpoint can generate a forced breakpoint or a tagged breakpoint. a forced breakpoint causes the cpu to enter active background mode at the first instruction boundary following any access to the breakpoint address. the tagged breakpoint causes the instruction opcode at the breakpoint address to be tagged so that the cpu will enter active background mode rather than executing that instruction if and when it reaches the end of the instruction queue. this implies that tagged breakpoints can only be placed at the address of an instruction opcode while forced breakpoints can be set at any address. the breakpoint enable (bkpten) control bit in the bdc status and control register (bdcscr) is used to enable the breakpoint logic (bkpten = 1). when bkpten = 0, its default value after reset, the breakpoint logic is disabled and no bdc breakpoints are requested regardless of the values in other bdc breakpoint registers and control bits. the force/tag select (fts) control bit in bdcscr is used to select forced (fts = 1) or tagged (fts = 0) type breakpoints. the on-chip debug module (dbg) includes circuitry for two additional hardware breakpoints that are more flexible than the simple breakpoint in the bdc module.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 193 mc9s08rc/rd/re/rg 14.4 on-chip debug system (dbg) because hcs08 devices do not have external address and data buses, the most important functions of an in-circuit emulator have been built onto the chip with the mcu. the debug system consists of an 8-stage fifo that can store address or data bus information, and a flexible trigger system to decide when to capture bus information and what information to capture. the system relies on the single-wire background debug system to access debug control registers and to read results out of the eight stage fifo. the debug module includes control and status registers that are accessible in the user? memory map. these registers are located in the high register space to avoid using valuable direct page memory space. most of the debug module? functions are used during development, and user programs rarely access any of the control and status registers for the debug module. the one exception is that the debug system can provide the means to implement a form of rom patching. this topic is discussed in greater detail in 14.4.6 hardware breakpoints . 14.4.1 comparators a and b two 16-bit comparators (a and b) can optionally be qualified with the r/w signal and an opcode tracking circuit. separate control bits allow you to ignore r/w for each comparator. the opcode tracking circuitry optionally allows you to specify that a trigger will occur only if the opcode at the specified address is actually executed as opposed to only being read from memory into the instruction queue. the comparators are also capable of magnitude comparisons to support the inside range and outside range trigger modes. comparators are disabled temporarily during all bdc accesses. the a comparator is always associated with the 16-bit cpu address. the b comparator compares to the cpu address or the 8-bit cpu data bus, depending on the trigger mode selected. because the cpu data bus is separated into a read data bus and a write data bus, the rwaen and rwa control bits have an additional purpose, in full address plus data comparisons they are used to decide which of these buses to use in the comparator b data bus comparisons. if rwaen = 1 (enabled) and rwa = 0 (write), the cpu? write data bus is used. otherwise, the cpu? read data bus is used. the currently selected trigger mode determines what the debugger logic does when a comparator detects a qualified match condition. a match can cause: generation of a breakpoint to the cpu storage of data bus values into the fifo starting to store change-of-flow addresses into the fifo (begin type trace) stopping the storage of change-of-flow addresses into the fifo (end type trace)
development support mc9s08rc/rd/re/rg 194 freescale semiconductor 14.4.2 bus capture information and fifo operation the usual way to use the fifo is to setup the trigger mode and other control options, then arm the debugger. when the fifo has filled or the debugger has stopped storing data into the fifo, you would read the information out of it in the order it was stored into the fifo. status bits indicate the number of words of valid information that are in the fifo as data is stored into it. if a trace run is manually halted by writing 0 to arm before the fifo is full (cnt = 1:0:0:0), the information is shifted by one position and the host must perform ((8 cnt) 1) dummy reads of the fifo to advance it to the first significant entry in the fifo. in most trigger modes, the information stored in the fifo consists of 16-bit change-of-flow addresses. in these cases, read dbgfh then dbgfl to get one coherent word of information out of the fifo. reading dbgfl (the low-order byte of the fifo data port) causes the fifo to shift so the next word of information is available at the fifo data port. in the event-only trigger modes (see 14.4.5 trigger modes ), 8-bit data information is stored into the fifo. in these cases, the high-order half of the fifo (dbgfh) is not used and data is read out of the fifo by simply reading dbgfl. each time dbgfl is read, the fifo is shifted so the next data value is available through the fifo data port at dbgfl. in trigger modes where the fifo is storing change-of-flow addresses, there is a delay between cpu addresses and the input side of the fifo. because of this delay, if the trigger event itself is a change-of-flow address or a change-of-flow address appears during the next two bus cycles after a trigger event starts the fifo, it will not be saved into the fifo. in the case of an end-trace, if the trigger event is a change-of-flow, it will be saved as the last change-of-flow entry for that debug run. the fifo can also be used to generate a profile of executed instruction addresses when the debugger is not armed. when arm = 0, reading dbgfl causes the address of the most-recently fetched opcode to be saved in the fifo. to use the profiling feature, a host debugger would read addresses out of the fifo by reading dbgfh then dbgfl at regular periodic intervals. the first eight values would be discarded because they correspond to the eight dbgfl reads needed to initially fill the fifo. additional periodic reads of dbgfh and dbgfl return delayed information about executed instructions so the host debugger can develop a profile of executed instruction addresses. 14.4.3 change-of-flow information to minimize the amount of information stored in the fifo, only information related to instructions that cause a change to the normal sequential execution of instructions is stored. with knowledge of the source and object code program stored in the target system, an external debugger system can reconstruct the path of execution through many instructions from the change-of-flow information stored in the fifo. for conditional branch instructions where the branch is taken (branch condition was true), the source address is stored (the address of the conditional branch opcode). because bra and brn instructions are not conditional, these events do not cause change-of-flow information to be stored in the fifo. indirect jmp and jsr instructions use the current contents of the h:x index register pair to determine the destination address, so the debug system stores the run-time destination address for any indirect jmp or jsr. for interrupts, rti, or rts, the destination address is stored in the fifo as change-of-flow information.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 195 mc9s08rc/rd/re/rg 14.4.4 tag vs. force breakpoints and triggers tagging is a term that refers to identifying an instruction opcode as it is fetched into the instruction queue, but not taking any other action until and unless that instruction is actually executed by the cpu. this distinction is important because any change-of-flow from a jump, branch, subroutine call, or interrupt causes some instructions that have been fetched into the instruction queue to be thrown away without being executed. a force-type breakpoint waits for the current instruction to finish and then acts upon the breakpoint request. the usual action in response to a breakpoint is to go to active background mode rather than continuing to the next instruction in the user application program. the tag vs. force terminology is used in two contexts within the debug module. the first context refers to breakpoint requests from the debug module to the cpu. the second refers to match signals from the comparators to the debugger control logic. when a tag-type break request is sent to the cpu, a signal is entered into the instruction queue along with the opcode so that if/when this opcode ever executes, the cpu will effectively replace the tagged opcode with a bgnd opcode so the cpu goes to active background mode rather than executing the tagged instruction. when the trgsel control bit in the dbgt register is set to select tag-type operation, the output from comparator a or b is qualified by a block of logic in the debug module that tracks opcodes and only produces a trigger to the debugger if the opcode at the compare address is actually executed. there is separate opcode tracking logic for each comparator so more than one compare event can be tracked through the instruction queue at a time. 14.4.5 trigger modes the trigger mode controls the overall behavior of a debug run. the 4-bit trg field in the dbgt register selects one of nine trigger modes. when trgsel = 1 in the dbgt register, the output of the comparator must propagate through an opcode tracking circuit before triggering fifo actions. the begin bit in dbgt chooses whether the fifo begins storing data when the qualified trigger is detected (begin trace), or the fifo stores data in a circular fashion from the time it is armed until the qualified trigger is detected (end trigger). a debug run is started by writing a 1 to the arm bit in the dbgc register, which sets the armf flag and clears the af and bf flags and the cnt bits in dbgs. a begin-trace debug run ends when the fifo gets full. an end-trace run ends when the selected trigger event occurs. any debug run can be stopped manually by writing a 0 to the arm bit or dbgen bit in dbgc. in all trigger modes except event-only modes, the fifo stores change-of-flow addresses. in event-only trigger modes, the fifo stores data in the low-order eight bits of the fifo. the begin control bit is ignored in event-only trigger modes and all such debug runs are begin type traces. when trgsel = 1 to select opcode fetch triggers, it is not necessary to use r/w in comparisons because opcode tags would only apply to opcode fetches that are always read cycles. it would also be unusual to specify trgsel = 1 while using a full mode trigger because the opcode value is normally known at a particular address.
development support mc9s08rc/rd/re/rg 196 freescale semiconductor the following trigger mode descriptions only state the primary comparator conditions that lead to a trigger. either comparator can usually be further qualified with r/w by setting rwaen (rwben) and the corresponding rwa (rwb) value to be matched against r/w. the signal from the comparator with optional r/w qualification is used to request a cpu breakpoint if brken = 1 and tag determines whether the cpu request will be a tag request or a force request. a-only ?trigger when the address matches the value in comparator a a or b ?trigger when the address matches either the value in comparator a or the value in comparator b a then b ?trigger when the address matches the value in comparator b but only after the address for another cycle matched the value in comparator a. there can be any number of cycles after the a match and before the b match. a and b data (full mode) ?this is called a full mode because address, data, and r/w (optionally) must match within the same bus cycle to cause a trigger event. comparator a checks address, the low byte of comparator b checks data, and r/w is checked against rwa if rwaen = 1. the high-order half of comparator b is not used. in full trigger modes it is not useful to specify a tag-type cpu breakpoint (brken = tag = 1), but if you do, the comparator b data match is ignored for the purpose of issuing the tag request to the cpu and the cpu breakpoint is issued when the comparator a address matches. a and not b data (full mode) ?address must match comparator a, data must not match the low half of comparator b, and r/w must match rwa if rwaen = 1. all three conditions must be met within the same bus cycle to cause a trigger. in full trigger modes it is not useful to specify a tag-type cpu breakpoint (brken = tag = 1), but if you do, the comparator b data match is ignored for the purpose of issuing the tag request to the cpu and the cpu breakpoint is issued when the comparator a address matches. event-only b (store data) ?trigger events occur each time the address matches the value in comparator b. trigger events cause the data to be captured into the fifo. the debug run ends when the fifo becomes full. a then event-only b (store data) after the address has matched the value in comparator a, a trigger event occurs each time the address matches the value in comparator b. trigger events cause the data to be captured into the fifo. the debug run ends when the fifo becomes full. inside range (a address b) a trigger occurs when the address is greater than or equal to the value in comparator a and less than or equal to the value in comparator b at the same time. outside range (address < a or address > b) ?a trigger occurs when the address is either less than the value in comparator a or greater than the value in comparator b.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 197 mc9s08rc/rd/re/rg 14.4.6 hardware breakpoints the brken control bit in the dbgc register may be set to 1 to allow any of the trigger conditions described in 14.4.5 trigger modes to be used to generate a hardware breakpoint request to the cpu. the tag bit in dbgc controls whether the breakpoint request will be treated as a tag-type breakpoint or a force-type breakpoint. a tag breakpoint causes the current opcode to be marked as it enters the instruction queue. if a tagged opcode reaches the end of the pipe, the cpu executes a bgnd instruction to go to active background mode rather than executing the tagged opcode. a force-type breakpoint causes the cpu to finish the current instruction and then go to active background mode. if the background mode has not been enabled (enbdm = 1) by a serial write_control command through the bkgd pin, the cpu will execute an swi instruction instead of going to active background mode. 14.5 registers and control bits this section contains the descriptions of the bdc and dbg registers and control bits. refer to the high-page register summary in the memory section of this data sheet for the absolute address assignments for all dbg registers. this section refers to registers and control bits only by their names. a freescale-provided equate or header file is used to translate these names into the appropriate absolute addresses. 14.5.1 bdc registers and control bits the bdc has two registers: the bdc status and control register (bdcscr) is an 8-bit register containing control and status bits for the background debug controller. the bdc breakpoint match register (bdcbkpt) holds a 16-bit breakpoint match address. these registers are accessed with dedicated serial bdc commands and are not located in the memory space of the target mcu (so they do not have addresses and cannot be accessed by user programs). some of the bits in the bdcscr have write limitations; otherwise, these registers may be read or written at any time. for example, the enbdm control bit may not be written while the mcu is in active background mode. (this prevents the ambiguous condition of the control bit forbidding active background mode while the mcu is already in active background mode.) also, the four status bits (bdmact, ws, wsf, and dvf) are read-only status indicators and can never be written by the write_control serial bdc command. the clock switch (clksw) control bit may be read or written at any time. 14.5.1.1 bdc status and control register (bdcscr) this register can be read or written by serial bdc commands (read_status and write_control) but is not accessible to user programs because it is not located in the normal memory map of the mcu.
development support mc9s08rc/rd/re/rg 198 freescale semiconductor figure 14-5 bdc status and control register (bdcscr) enbdm enable bdm (permit active background mode) typically, this bit is written to 1 by the debug host shortly after the beginning of a debug session or whenever the debug host resets the target and remains 1 until a normal reset clears it. 1 = bdm can be made active to allow active background mode commands. 0 = bdm cannot be made active (non-intrusive commands still allowed). bdmact background mode active status this is a read-only status bit. 1 = bdm active and waiting for serial commands. 0 = bdm not active (user application program running). bkpten bdc breakpoint enable if this bit is clear, the bdc breakpoint is disabled and the fts (force tag select) control bit and bdcbkpt match register are ignored. 1 = bdc breakpoint enabled. 0 = bdc breakpoint disabled. fts force/tag select when fts = 1, a breakpoint is requested whenever the cpu address bus matches the bdcbkpt match register. when fts = 0, a match between the cpu address bus and the bdcbkpt register causes the fetched opcode to be tagged. if this tagged opcode ever reaches the end of the instruction queue, the cpu enters active background mode rather than executing the tagged opcode. 1 = breakpoint match forces active background mode at next instruction boundary (address need not be an opcode). 0 = tag opcode at breakpoint address and enter active background mode if cpu attempts to execute that instruction. clksw select source for bdc communications clock clksw defaults to 0, which selects the alternate bdc clock source. 1 = mcu bus clock. 0 = alternate bdc clock source. bit 7 6 5 4321 bit 0 read: enbdm bdmact bkpten fts clksw ws wsf dvf write: normal reset: 0 0 0 00000 reset in active bdm: 1 1 0 01000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 199 mc9s08rc/rd/re/rg ws wait or stop status when the target cpu is in wait or stop mode, most bdc commands cannot function. however, the background command can be used to force the target cpu out of wait or stop and into active background mode where all bdc commands work. whenever the host forces the target mcu into active background mode, the host should issue a read_status command to check that bdmact = 1 before attempting other bdc commands. 1 = target cpu is in wait or stop mode, or a background command was used to change from wait or stop to active background mode. 0 = target cpu is running user application code or in active background mode (was not in wait or stop mode when background became active). wsf wait or stop failure status this status bit is set if a memory access command failed due to the target cpu executing a wait or stop instruction at or about the same time. the usual recovery strategy is to issue a background command to get out of wait or stop mode into active background mode, repeat the command that failed, then return to the user program. (typically, the host would restore cpu registers and stack values and re-execute the wait or stop instruction.) 1 = memory access command failed because the cpu entered wait or stop mode. 0 = memory access did not conflict with a wait or stop instruction. dvf data valid failure status this status bit is not used in the mc9s08rc/rd/re/rg because it does not have any slow access memory. 1 = memory access command failed because cpu was not finished with a slow memory access. 0 = memory access did not conflict with a slow memory access. 14.5.1.2 bdc breakpoint match register (bdcbkpt) this 16-bit register holds the address for the hardware breakpoint in the bdc. the bkpten and fts control bits in bdcscr are used to enable and configure the breakpoint logic. dedicated serial bdc commands (read_bkpt and write_bkpt) are used to read and write the bdcbkpt register but is not accessible to user programs because it is not located in the normal memory map of the mcu. breakpoints are normally set while the target mcu is in active background mode before running the user application program. for additional information about setup and use of the hardware breakpoint logic in the bdc, refer to 14.3.4 bdc hardware breakpoint . 14.5.2 system background debug force reset register (sbdfr) this register contains a single write-only control bit. a serial active background mode command such as write_byte must be used to write to sbdfr. attempts to write this register from a user program are ignored. reads always return $00.
development support mc9s08rc/rd/re/rg 200 freescale semiconductor figure 14-6 system background debug force reset register (sbdfr) bdfr background debug force reset a serial active background mode command such as write_byte allows an external debug host to force a target system reset. writing logic 1 to this bit forces an mcu reset. this bit cannot be written from a user program. 14.5.3 dbg registers and control bits the debug module includes nine bytes of register space for three 16-bit registers and three 8-bit control and status registers. these registers are located in the high register space of the normal memory map so they are accessible to normal application programs. these registers are rarely if ever accessed by normal user application programs with the possible exception of a rom patching mechanism that uses the breakpoint logic. 14.5.3.1 debug comparator a high register (dbgcah) this register contains compare value bits for the high-order eight bits of comparator a. this register is forced to $00 at reset and can be read at any time or written at any time unless arm = 1. 14.5.3.2 debug comparator a low register (dbgcal) this register contains compare value bits for the low-order eight bits of comparator a. this register is forced to $00 at reset and can be read at any time or written at any time unless arm = 1. 14.5.3.3 debug comparator b high register (dbgcbh) this register contains compare value bits for the high-order eight bits of comparator b. this register is forced to $00 at reset and can be read at any time or written at any time unless arm = 1. 14.5.3.4 debug comparator b low register (dbgcbl) this register contains compare value bits for the low-order eight bits of comparator b. this register is forced to $00 at reset and can be read at any time or written at any time unless arm = 1. bit 7 654321 bit 0 read: 00000000 write: bdfr (1) notes : 1. bdfr is writable only through serial active background mode debug commands, not from user programs. reset: 00010000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 201 mc9s08rc/rd/re/rg 14.5.3.5 debug fifo high register (dbgfh) this register provides read-only access to the high-order eight bits of the fifo. writes to this register have no meaning or effect. in the event-only trigger modes, the fifo only stores data into the low-order byte of each fifo word, so this register is not used and will read $00. reading dbgfh does not cause the fifo to shift to the next word. when reading 16-bit words out of the fifo, read dbgfh before reading dbgfl because reading dbgfl causes the fifo to advance to the next word of information. 14.5.3.6 debug fifo low register (dbgfl) this register provides read-only access to the low-order eight bits of the fifo. writes to this register have no meaning or effect. reading dbgfl causes the fifo to shift to the next available word of information. when the debug module is operating in event-only modes, only 8-bit data is stored into the fifo (high-order half of each fifo word is unused). when reading 8-bit words out of the fifo, simply read dbgfl repeatedly to get successive bytes of data from the fifo. it isn? necessary to read dbgfh in this case. do not attempt to read data from the fifo while it is still armed (after arming but before the fifo is filled or armf is cleared) because the fifo is prevented from advancing during reads of dbgfl. this can interfere with normal sequencing of reads from the fifo. reading dbgfl while the debugger is not armed causes the address of the most-recently fetched opcode to be stored to the last location in the fifo. by reading dbgfh then dbgfl periodically, external host software can develop a profile of program execution. after eight reads from the fifo, the ninth read will return the information that was stored as a result of the first read. to use the profiling feature, read the fifo eight times without using the data to prime the sequence and then begin using the data to get a delayed picture of what addresses were being executed. the information stored into the fifo on reads of dbgfl (while the fifo is not armed) is the address of the most-recently fetched opcode. 14.5.3.7 debug control register (dbgc) this register can be read or written at any time. figure 14-7 debug control register (dbgc) dbgen debug module enable used to enable the debug module. dbgen cannot be set to 1 if the mcu is secure. 1 = dbg enabled. 0 = dbg disabled. bit 7 6 5 4321 bit 0 read: dbgen arm tag brken rwa rwaen rwb rwben write: reset: 0 0 0 00000
development support mc9s08rc/rd/re/rg 202 freescale semiconductor arm arm control controls whether the debugger is comparing and storing information in the fifo. a write is used to set this bit (and the armf bit) and completion of a debug run automatically clears it. any debug run can be manually stopped by writing 0 to arm or to dbgen. 1 = debugger armed. 0 = debugger not armed. tag tag/force select controls whether break requests to the cpu will be tag or force type requests. if brken = 0, this bit has no meaning or effect. 1 = cpu breaks requested as tag type requests. 0 = cpu breaks requested as force type requests. brken break enable controls whether a trigger event will generate a break request to the cpu. trigger events can cause information to be stored in the fifo without generating a break request to the cpu. for an end trace, cpu break requests are issued to the cpu when the comparator(s) and r/w meet the trigger requirements. for a begin trace, cpu break requests are issued when the fifo becomes full. trgsel does not affect the timing of cpu break requests. 1 = triggers cause a break request to the cpu. 0 = cpu break requests not enabled. rwa r/w comparison value for comparator a when rwaen = 1, this bit determines whether a read or a write access qualifies comparator a. when rwaen = 0, rwa and the r/w signal do not affect comparator a. 1 = comparator a can only match on a read cycle. 0 = comparator a can only match on a write cycle. rwaen enable r/w for comparator a controls whether the level of r/w is considered for a comparator a match. 1 = r/w is used in comparison a. 0 = r/w is not used in comparison a. rwb r/w comparison value for comparator b when rwben = 1, this bit determines whether a read or a write access qualifies comparator b. when rwben = 0, rwb and the r/w signal do not affect comparator b. 1 = comparator b can match only on a read cycle. 0 = comparator b can match only on a write cycle. rwben enable r/w for comparator b controls whether the level of r/w is considered for a comparator b match. 1 = r/w is used in comparison b. 0 = r/w is not used in comparison b.
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 203 mc9s08rc/rd/re/rg 14.5.3.8 debug trigger register (dbgt) this register can be read any time, but may be written only if arm = 0, except bits 4 and 5 are hard-wired to 0s. figure 14-8 debug trigger register (dbgt) trgsel trigger type controls whether the match outputs from comparators a and b are qualified with the opcode tracking logic in the debug module. if trgsel is set, a match signal from comparator a or b must propagate through the opcode tracking logic and a trigger event is only signalled to the fifo logic if the opcode at the match address is actually executed. 1 = trigger if opcode at compare address is executed (tag). 0 = trigger on access to compare address (force). begin begin/end trigger select controls whether the fifo starts filling at a trigger or fills in a circular manner until a trigger ends the capture of information. in event-only trigger modes, this bit is ignored and all debug runs are assumed to be begin traces. 1 = trigger initiates data storage (begin trace). 0 = data stored in fifo until trigger (end trace). trg3:trg2:trg1:trg0 select trigger mode selects one of nine triggering modes bit 7 6 5 4321 bit 0 read: trgsel begin 00 trg3 trg2 trg1 trg0 write: reset: 0 0 0 00000 = unimplemented or reserved
development support mc9s08rc/rd/re/rg 204 freescale semiconductor 14.5.3.9 debug status register (dbgs) this is a read-only status register. figure 14-9 debug status register (dbgs) af trigger match a flag af is cleared at the start of a debug run and indicates whether a trigger match a condition was met since arming. 1 = comparator a match. 0 = comparator a has not matched. bf trigger match b flag bf is cleared at the start of a debug run and indicates whether a trigger match b condition was met since arming. 1 = comparator b match. 0 = comparator b has not matched. table 14-2 trigger mode selection trg[3:0] triggering mode 0000 a-only 0001 a or b 0010 a then b 0011 event-only b (store data) 0100 a then event-only b (store data) 0101 a and b data (full mode) 0110 a and not b data (full mode) 0111 inside range: a address b 1000 outside range: address < a or address > b 1001 ?1111 no trigger bit 7 6 5 4321 bit 0 read: af bf armf 0 cnt3 cnt2 cnt1 cnt0 write: reset: 0 0 0 00000 = unimplemented or reserved
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 205 mc9s08rc/rd/re/rg armf arm flag while dbgen = 1, this status bit is a read-only image of the arm bit in dbgc. this bit is set by writing 1 to the arm control bit in dbgc (while dbgen = 1) and is automatically cleared at the end of a debug run. a debug run is completed when the fifo is full (begin trace) or when a trigger event is detected (end trace). a debug run can also be ended manually by writing 0 to the arm or dbgen bits in dbgc. 1 = debugger armed. 0 = debugger not armed. cnt3:cnt2:cnt1:cnt0 fifo valid count these bits are cleared at the start of a debug run and indicate the number of words of valid data in the fifo at the end of a debug run. the value in cnt does not decrement as data is read out of the fifo. the external debug host is responsible for keeping track of the count as information is read out of the fifo. table 14-3 cnt status bits cnt[3:0] valid words in fifo 0000 no valid data 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8
development support mc9s08rc/rd/re/rg 206 freescale semiconductor
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 207 mc9s08rc/rd/re/rg appendix c electrical characteristics c.1 introduction this section contains electrical and timing specifications. c.2 absolute maximum ratings absolute maximum ratings are stress ratings only, and functional operation at the maxima is not guaranteed. stress beyond the limits specified in table c-1 may affect device reliability or cause permanent damage to the device. for functional operating conditions, refer to the remaining tables in this section. this device contains circuitry protecting against damage due to high static voltage or electrical fields; however, it is advised that normal precautions be taken to avoid application of any voltages higher than maximum-rated voltages to this high-impedance circuit. reliability of operation is enhanced if unused inputs are tied to an appropriate logic voltage level (for instance, either v ss or v dd ) or the programmable pull-up resistor associated with the pin is enabled. table c-1 absolute maximum ratings rating symbol value unit supply voltage v dd ?.3 to +3.8 v maximum current into v dd i dd 120 ma digital input voltage v in ?.3 to v dd + 0.3 v instantaneous maximum current single pin limit (applies to all port pins) (1) , (2) , (3) notes : 1. input must be current limited to the value specified. to determine the value of the required current-limiting resistor, calculate resistance values for positive (v dd ) and negative (v ss ) clamp voltages, then use the larger of the two resistance values. 2. all functional non-supply pins are internally clamped to v ss and v dd . 3. power supply must maintain regulation within operating v dd range during instantaneous and operating maximum current conditions. if positive injection current (v in >v dd )is greater than i dd , the injection current may flow out of v dd and could result in external power supply going out of regulation. ensure external v dd load will shunt current greater than maximum injection current. this will be the greatest risk when the mcu is not consuming power. examples are: if no system clock is present, or if the clock rate is very low (which would reduce overall power consumption). i d 25 ma storage temperature range t stg ?5 to 150 c
electrical characteristics mc9s08rc/rd/re/rg 208 freescale semiconductor c.3 thermal characteristics this section provides information about operating temperature range, power dissipation, and package thermal resistance. power dissipation on i/o pins is usually small compared to the power dissipation in on-chip logic and voltage regulator circuits and it is user-determined rather than being controlled by the mcu design. in order to take p i/o into account in power calculations, determine the difference between actual pin voltage and v ss or v dd and multiply by the pin current for each i/o pin. except in cases of unusually high pin current (heavy loads), the difference between pin voltage and v ss or v dd will be very small. the average chip-junction temperature (t j ) in c can be obtained from: equation 1 t j = t a + (p d ja ) where: t a = ambient temperature, c ja = package thermal resistance, junction-to-ambient, c/w p d = p int + p i/o p int = i dd v dd , watts ?chip internal power p i/o = power dissipation on input and output pins ?user determined for most applications, p i/o << p int and can be neglected. an approximate relationship between p d and t j (if p i/o is neglected) is: equation 2 p d = k (t j + 273 c) solving equations 1 and 2 for k gives: equation 3 k = p d (t a + 273 c) + ja (p d ) 2 where k is a constant pertaining to the particular part. k can be determined from equation 3 by measuring p d (at equilibrium) for a known t a . using this value of k, the values of p d and t j can be obtained by solving equations 1 and 2 iteratively for any value of t a . table c-2 thermal characteristics rating symbol value unit operating temperature range (packaged) t a t l to t h ?0 to 85 c thermal resistance 28-pin pdip 28-pin soic 32-pin lqfp 44-pin lqfp ja 75 70 72 70 c/w
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 209 mc9s08rc/rd/re/rg c.4 electrostatic discharge (esd) protection characteristics although damage from static discharge is much less common on these devices than on early cmos circuits, normal handling precautions should be used to avoid exposure to static discharge. qualification tests are performed to ensure that these devices can withstand exposure to reasonable levels of static without suffering any permanent damage. all esd testing is in conformity with cdf-aec-q00 stress test qualification for automotive grade integrated circuits. (http://www.aecouncil.com/) a device is considered to have failed if, after exposure to esd pulses, the device no longer meets the device specification requirements. complete dc parametric and functional testing is performed per the applicable device data sheet at room temperature followed by hot temperature, unless specified otherwise in the device data sheet. c.5 dc characteristics this section includes information about power supply requirements, i/o pin characteristics, and power supply current in various operating modes. table c-3 esd protection characteristics parameter symbol value unit esd target for machine model (mm) mm circuit description v thmm 200 v esd target for human body model (hbm) hbm circuit description v thhbm 2000 v table c-4 dc characteristics (temperature range = 0 to 70 c ambient) parameter symbol min typical max unit low-voltage detection threshold v lv d 1.82 1.875 1.90 v power on reset (por) voltage v por 0.8 0.9 1.0 v maximum low-voltage safe state re-arm (1) notes : 1. if safe bit is set, v dd must be above re-arm voltage to allow mcu to accept interrupts, refer to 5.6 low-voltage detect (lvd) system . v rearm 1.90 2.24 2.60 v table c-5 dc characteristics (temperature range = ?0 to 85 c ambient) parameter symbol min typical max unit supply voltage (run, wait and stop modes.) 0 < f bus < 8 mhz v dd 1.8 3.6 v minimum ram retention supply voltage applied to v dd v ram v por (1), (2) ? low-voltage detection threshold (v dd falling) (v dd rising) v lv d 1.82 1.92 1.88 1.96 1.93 2.01 v
electrical characteristics mc9s08rc/rd/re/rg 210 freescale semiconductor low-voltage warning threshold (v dd falling) (v dd rising) v lv w 2.07 2.16 2.13 2.21 2.18 2.26 v power on reset (por) voltage v por 0.85 1.0 1.2 v maximum low-voltage safe state re-arm (3) v rearm 3.0 v input high voltage (v dd > 2.3 v) (all digital inputs) v ih 0.70 v dd ? input high voltage (1.8 v v dd 2.3 v) (all digital inputs) v ih 0.85 v dd ? input low voltage (v dd > 2.3 v) (all digital inputs) v il 0.35 v dd v input low voltage (1.8 v v dd 2.3 v) (all digital inputs) v il 0.30 v dd v input hysteresis (all digital inputs) v hys 0.06 v dd ? input leakage current (per pin) v in = v dd or v ss, all input only pins |i in | 0.025 1.0 a high impedance (off-state) leakage current (per pin) v in = v dd or v ss , all input/output |i oz | 0.025 1.0 a internal pullup resistors (4) (5) r pu 17.5 52.5 k ? internal pulldown resistor (irq) r pd 17.5 52.5 k ? output high voltage (v dd 1.8 v) i oh = ? ma (ports a, c, d and e) v oh v dd ?0.5 v output high voltage (port b and iro) i oh = ?0 ma (v dd 2.7 v) i oh = ? ma (v dd 2.3 v) i oh = ? ma (v dd 1.8 v) v dd ?0.5 maximum total i oh for all port pins |i oht | ?0ma output low voltage (v dd 1.8 v) i ol = 2.0 ma (ports a, c, d and e) v ol 0.5 v output low voltage (port b) i ol = 10.0 ma (v dd 2.7 v) i ol = 6 ma (v dd 2.3 v) i ol = 3 ma (v dd 1.8 v) 0.5 0.5 0.5 output low voltage (iro) i ol = 16 ma (v dd 2.7 v) i ol =tbd ma (v dd 2.3 v) i ol = tbd ma (v dd 1.8 v) 1.2 1.2 1.2 maximum total i ol for all port pins i olt ?0ma dc injection current (2), (6), (7), (8),, (9) v in < v ss , v in > v dd single pin limit total mcu limit, includes sum of all stressed pins |i ic | 0.2 5 ma ma input capacitance (all non-supply pins) c in ?pf table c-5 dc characteristics (continued)(temperature range = ?0 to 85 c ambient) parameter symbol min typical max unit
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 211 mc9s08rc/rd/re/rg figure c-1 pullup and pulldown typical resistor values (v dd = 3.0 v) figure c-2 typical low-side driver (sink) characteristics (port b and iro) notes : 1. ram will retain data down to por voltage. ram data not guaranteed to be valid following a por. 2. this parameter is characterized and not tested on each device. 3. if safe bit is set, v dd must be above re-arm voltage to allow mcu to accept interrupts, refer to 5.6 low-voltage detect (lvd) system . 4. measurement condition for pull resistors: v in = v ss for pullup and v in = v dd for pulldown. 5. the pta0 pullup resistor may not pull up to the specified minimum v ih . however, all ports are functionally tested to guarantee that a logic 1 will be read on any port input when the pullup is enabled and no dc load is present on the pin. in addition, the test checks that the pin is pulled up from v ss to a logic 1 within 20 s with a nominal capacitance of 75 pf. 6. all functional non-supply pins are internally clamped to v ss and v dd . 7. input must be current limited to the value specified. to determine the value of the required current-limiting resistor, calculate resistance values for positive and negative clamp voltages, then use the larger of the two values. 8. power supply must maintain regulation within operating v dd range during instantaneous and operating maximum current conditions. if positive injection current (v in >v dd ) is greater than i dd , the injection current may flow out of v dd and could result in external power supply going out of regulation. ensure external v dd load will shunt current greater than maximum injection current. this will be the greatest risk when the mcu is not consuming power. examples are: if no system clock is present, or if clock rate is very low (which would reduce overall power consumption). 9. pta0 does not have a clamp diode to v dd . do not drive pta0 above v dd . pullup resistor typicals v dd (v) pull-up resistor (k ? ) 20 25 30 35 40 1.8 2 2.2 2.4 2.6 2.8 3 3.2 3.4 3.6 25 c 85 c ?0 c pulldown resistor typicals v dd (v) pulldown resistance (k ? ) 20 25 30 35 40 1.8 2.3 2.8 3.3 25 c 85 c ?0 c 3.6 typical v ol vs i ol at v dd = 3.0 v i ol (ma) v ol (v) 0 0.2 0.4 0.6 0.8 1 0102030 typi c al v ol v s v dd v dd (v) v ol (v) 0 0.1 0.2 0.3 0.4 1234 i ol = 6 ma i ol = 3 ma i ol = 10 ma 25 c 85 c ?0 c 25 c 85 c ?0 c
electrical characteristics mc9s08rc/rd/re/rg 212 freescale semiconductor figure c-3 typical low-side driver (sink) characteristics (ports a, c, d and e) figure c-4 typical high-side driver (source) characteristics (port b and iro) figure c-5 typical high-side (source) characteristics (ports a, c, d and e) typical v ol vs i ol at v dd = 3.0 v i ol (ma) v ol (v) 0 0.2 0.4 0.6 0.8 1 1.2 0 5 10 15 20 typical v ol vs v dd v dd (v) v ol (v) 0 0.05 0.1 0.15 0.2 1234 25 c 85 c ?0 c 25 c, i ol = 2 ma 85 c, i ol = 2 ma ?0 c, i ol = 2 ma typical v dd ?v oh vs i oh at v dd = 3.0 v i oh (ma) 0 0.2 0.4 0.6 0.8 ?0 ?5 ?0 ?5 ?0 ? 0 typical v dd ?v oh vs v dd at spec i oh v dd (v) v dd ?v oh (v) 0 0.1 0.2 0.3 0.4 1234 i oh = ?0 ma i oh = ? ma i oh = ? ma v dd ?v oh (v) 25 c 85 c ?0 c 25 c 85 c ?0 c typical v dd ?v oh vs i oh at v dd = 3.0 v i oh (ma)) 0 0.2 0.4 0.6 0.8 1 1.2 ?0 ?5 ?0 ? 0 typical v dd ?v oh vs v dd at spec i oh v dd (v) v dd ?v oh (v) 0 0.05 0.1 0.15 0.2 0.25 1234 v dd ?v oh (v) 25 c 85 c ?0 c 25 c, i oh = 2 ma 85 c, i oh = 2 ma ?0 c, i oh = 2 ma
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 213 mc9s08rc/rd/re/rg c.6 supply current characteristics table c-6 supply current characteristics parameter symbol v dd (v) (1) notes : 1. 3 v values are 100% tested; 2 v values are characterized but not tested. typical (2) 2. typicals are measured at 25 c. max temp. ( c) run supply current (3) measured at (cpu clock = 2 mhz, f bus = 1 mhz) 3. does not include any dc loads on port pins ri dd 3 500 a 1.525 ma 1.525 ma 70 85 2 450 a 1.475 ma 1.475 ma 70 85 run supply current (3) measured at (cpu clock = 16 mhz, f bus = 8 mhz) ri dd 3 3.8 ma 4.8 ma 4.8 ma 70 85 2 2.6 ma 3.6 ma 3.6 ma 70 85 stop1 mode supply current s1i dd 3 100 na 350 na 736 na 70 85 2 100 na 150 na 450 na 70 85 stop2 mode supply current s2i dd 3 500 na 1.20 a 1.90 a 70 85 2 500 na 1.00 a 1.70 a 70 85 stop3 mode supply current s3i dd 3 600 na 2.65 a 4.65 a 70 85 2 500 na 2.30 a 4.30 a 70 85 rti adder from stop2 or stop3 3 300 na 2 300 na adder for lvd reset enabled in stop3 370 a 260 a
electrical characteristics mc9s08rc/rd/re/rg 214 freescale semiconductor c.7 analog comparator (acmp) electricals c.8 oscillator characteristics table c-7 acmp electrical speci?ations (temp range = -40 to 85 c ambient) characteristic symbol min typical max unit analog input voltage v ain v ss ?0.3 v dd v analog input offset voltage v aio ?0mv analog comparator initialization delay t ainit ? s analog comparator bandgap reference voltage v bg 1.208 1.218 1.228 v table c-8 osc electrical speci?ations (temperature range = -40 to 85 c ambient) characteristic symbol min typ (1) notes : 1. data in typical column was characterized at 3.0 v, 25 c or is typical recommended value. max unit frequency f osc 1 16 mhz load capacitors c 1 c 2 (2) 2. see crystal or resonator manufacturer? recommendation. feedback resistor r f 1m ? osc extal xtal crystal or resonator c 2 r f c 1
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 215 mc9s08rc/rd/re/rg c.9 ac characteristics this section describes ac timing characteristics for each peripheral system. c.9.1 control timing figure c-6 reset timing table c-9 control timing parameter symbol min typical max unit bus frequency (t cyc = 1/f bus )f bus dc 8 mhz real time interrupt internal oscillator f rti 700 1300 hz external reset pulse width (1) notes : 1. this is the shortest pulse that is guaranteed to be recognized as a reset pin request. shorter pulses are not guaranteed to override reset requests from internal sources. t extrst 1.5 t cyc ?s reset low drive (2) 2. when any reset is initiated, internal circuitry drives the reset pin low for about 34 cycles of f bus and then samples the level on the reset pin about 38 cycles later to distinguish external reset requests from internal requests. t rstdrv 34 t cyc ?s active background debug mode latch setup time t mssu 25 ns active background debug mode latch hold time t msh 25 ns irq pulse width (3) 3. this is the minimum pulse width that is guaranteed to pass through the pin synchronization circuitry. shorter pulses may or may not be recognized. in stop mode, the synchronizer is bypassed so shorter pulses can be recognized in that case. t ilih 1.5 t cyc ?s port rise and fall time (load = 50 pf) (4) 4. timing is shown with respect to 20% v dd and 80% v dd levels. temperature range ?0 c to 85 c. t rise , t fall ? ns t extrst reset pin
electrical characteristics mc9s08rc/rd/re/rg 216 freescale semiconductor figure c-7 active background debug mode latch timing figure c-8 irq timing c.9.2 timer/pwm (tpm) module timing synchronizer circuits determine the shortest input pulses that can be recognized or the fastest clock that can be used as the optional external source to the timer counter. these synchronizers operate from the current bus rate clock. figure c-9 timer external clock table c-10 tpm input timing function symbol min max unit external clock frequency f tpmext dc f bus /4 mhz external clock period t tpmext 4 t cyc external clock high time t clkh 1.5 t cyc external clock low time t clkl 1.5 t cyc input capture pulse width t icpw 1.5 t cyc bkgd/ms reset t mssu t msh t ilih irq t text t clkh t clkl tpm1chn
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 217 mc9s08rc/rd/re/rg figure c-10 timer input capture pulse c.9.3 spi timing table c-11 and figure c-11 through figure c-14 describe the timing requirements for the spi system. table c-11 spi timing no. function symbol min max unit operating frequency master slave f op f bus /2048 dc f bus /2 f bus /4 hz 1 spsck period master slave t spsck 2 4 2048 t cyc t cyc 2 enable lead time master slave t lead 1 / 2 1 t spsck t cyc 3 enable lag time master slave t lag 1 / 2 1 t spsck t cyc 4 clock (spsck) high or low time master slave t wspsck t cyc ?0 t cyc ?30 1024 t cyc ns ns 5 data setup time (inputs) master slave t su 15 15 ns ns 6 data hold time (inputs) master slave t hi 0 25 ns ns 7 slave access time t a ?t cyc 8 slave miso disable time t dis ?t cyc 9 data valid (after spsck edge) master slave t v 25 25 ns ns t icpw tpm1chn t icpw tpm1chn
electrical characteristics mc9s08rc/rd/re/rg 218 freescale semiconductor figure c-11 spi master timing (cpha = 0) 10 data hold time (outputs) master slave t ho 0 0 ns ns 11 rise time input output t ri t ro t cyc ?25 25 ns ns 12 fall time input output t fi t fo t cyc ?25 25 ns ns table c-11 spi timing (continued) no. function symbol min max unit spsck (output) spsck (output) miso (input) mosi (output) ss 1 (output) msb in 2 bit 6 . . . 1 lsb in msb out 2 lsb out bit 6 . . . 1 (cpol = 0) (cpol = 1) notes: 2. lsbf = 0. for lsbf = 1, bit order is lsb, bit 1, ..., bit 6, msb. 1. ss output mode (dds7 = 1, ssoe = 1). 1 2 3 4 5 6 9 10 11 12 4 9
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 219 mc9s08rc/rd/re/rg figure c-12 spi master timing (cpha =1) figure c-13 spi slave timing (cpha = 0) spsck (output) spsck (output) miso (input) mosi (output) msb in (2) bit 6 . . . 1 lsb in master msb out (2) master lsb out bit 6 . . . 1 port data (cpol = 0) (cpol = 1) port data ss (1) (output) 1. ss output mode (dds7 = 1, ssoe = 1). 2. lsbf = 0. for lsbf = 1, bit order is lsb, bit 1, ..., bit 6, msb. notes: 2 1 12 11 3 4 4 11 12 5 6 9 10 spsck (input) spsck (input) mosi (input) miso (output) ss (input) msb in bit 6 . . . 1 lsb in msb out slave lsb out bit 6 . . . 1 (cpol = 0) (cpol = 1) note: slave see note 1. not defined but normally msb of character just received 1 2 3 4 5 6 7 8 9 10 11 12 4 11 12 10
electrical characteristics mc9s08rc/rd/re/rg 220 freescale semiconductor figure c-14 spi slave timing (cpha = 1) spsck (input) spsck (input) mosi (input) miso (output) msb in bit 6 . . . 1 lsb in msb out slave lsb out bit 6 . . . 1 see (cpol = 0) (cpol = 1) ss (input) note: slave note 1. not defined but normally lsb of character just received 1 2 3 4 5 6 7 8 9 10 11 12 4 11 12
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 221 mc9s08rc/rd/re/rg c.10 flash specifications this section provides details about program/erase times and program-erase endurance for the flash memory. program and erase operations do not require any special power sources other than the normal v dd supply. for more detailed information about program/erase operations, see the memory section. table c-12 flash characteristics characteristic symbol min typical max unit supply voltage for program/erase v prog/erase 2.05 3.6 v supply voltage for read operation 0 < f bus < 8 mhz v read 1.8 3.6 v internal fclk frequency (1) notes : 1. the frequency of this clock is controlled by a software setting. f fclk 150 200 khz internal fclk period (1/fclk) t fcyc 5 6.67 s byte program time (random location) (2) t prog 9 t fcyc byte program time (burst mode) (2) t burst 4 t fcyc page erase time (2) 2. these values are hardware state machine controlled. user code does not need to count cycles. this information supplied for calculating approximate time to program and erase. t page 4000 t fcyc mass erase time (2) t mass 20,000 t fcyc program/erase endurance (3) t l to t h = ?0 c to + 85 c t = 25 c 3. typical endurance for flash was evaluated for this product family on the 9s12dx64. for additional information on how freescale semiconductor defines typical endurance, please refer to engineering bulletin eb619/d, typical endurance for nonvolatile memory . 10,000 100,000 cycles data retention (4) 4. typical data retention values are based on intrinsic capability of the technology measured at high temperature and de-rated to 25 c using the arrhenius equation. for additional information on how freescale semiconductor defines typical data retention, please refer to engineering bulletin eb618/d, typical data retention for nonvolatile memory. t d_ret 15 100 years
electrical characteristics mc9s08rc/rd/re/rg 222 freescale semiconductor
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 223 mc9s08rc/rd/re/rg appendix d ordering information and mechanical drawings d.1 ordering information this section contains ordering numbers for mc9s08rc/rd/re/rg devices. see below for an example of the device numbering system. table 14-4 orderable part numbers mc order number flash memory ram acmp sci spi available package type (part number suffix) mc9s08rg32(c)fj 32k 2k yes yes yes 32 lqfp (fj) mc9s08rg32(c)fg 32k 2k yes yes yes 44 lqfp (fg) MC9S08RG60(c)fj 60k 2k yes yes yes 32 lqfp (fj) MC9S08RG60(c)fg 60k 2k yes yes yes 44 lqfp (fg) mc9s08re8(c)fj 8k 1k yes yes no 32 lqfp (fj) mc9s08re8(c)fg 8k 1k yes yes no 44 lqfp (fg) mc9s08re16(c)fj 16k 1k yes yes no 32 lqfp (fj) mc9s08re16(c)fg 16k 1k yes yes no 44 lqfp (fg) mc9s08re32(c)fj 32k 2k yes yes no 32 lqfp (fj) mc9s08re32(c)fg 32k 2k yes yes no 44 lqfp (fg) mc9s08re60(c)fj 60k 2k yes yes no 32 lqfp (fj) mc9s08re60(c)fg 60k 2k yes yes no 44 lqfp (fg) mc9s08rd8(c)pe 8k 1k no yes no 28 pdip (p) mc9s08rd8(c)dwe 8k 1k no yes no 28 soic (dw) mc9s08rd8(c)fj 8k 1k no yes no 32 lqfp (fj) mc9s08rd8(c)fg 8k 1k no yes no 44 lqfp (fg) mc9s08rd16(c)pe 16k 1k no yes no 28 pdip (p) mc9s08rd16(c)dwe 16k 1k no yes no 28 soic (dw) mc9s08rd16(c)fj 16k 1k no yes no 32 lqfp (fj) mc9s08rd16(c)fg 16k 1k no yes no 44 lqfp (fg) mc9s08rd32(c)pe 32k 2k no yes no 28 pdip (p) mc9s08rd32(c)dwe 32k 2k no yes no 28 soic (dw) mc9s08rd32(c)fj 32k 2k no yes no 32 lqfp (fj)
ordering information and mechanical drawings mc9s08rc/rd/re/rg 224 freescale semiconductor package designators: dw =28-pin small outline integrated circuit (soic) p = 28-pin plastic dual in-line package (pdip) fg = 44-pin low quad flat package (lqfp) fj = 32-pin low quad flat package (lqfp) d.2 mechanical drawings this appendix contains mechanical specification for mc9s08rc/rd/re/rg mcu. mc9s08rd32(c)fg 32k 2k no yes no 44 lqfp (fg) mc9s08rd60(c)pe 60k 2k no yes no 28 pdip (p) mc9s08rd60(c)dwe 60k 2k no yes no 28 soic (dw) mc9s08rd60(c)fj 60k 2k no yes no 32 lqfp (fj) mc9s08rd60(c)fg 60k 2k no yes no 44 lqfp (fg) mc9s08rc8(c)fj 8k 1k yes no no 32 lqfp (fj) mc9s08rc8(c)fg 8k 1k yes no no 44 lqfp (fg) mc9s08rc16(c)fj 16k 1k yes no no 32 lqfp (fj) mc9s08rc16(c)fg 16k 1k yes no no 44 lqfp (fg) mc9s08rc32(c)fj 32k 2k yes no no 32 lqfp (fj) mc9s08rc32(c)fg 32k 2k yes no no 44 lqfp (fg) mc9s08rc60(c)fj 60k 2k yes no no 32 lqfp (fj) mc9s08rc60(c)fg 60k 2k yes no no 44 lqfp (fg) table 14-4 orderable part numbers (continued) mc order number flash memory ram acmp sci spi available package type (part number suffix) mc 9 s08 rg60 (c) xx e family memory status core type package designator indicates lead-free packag temperature range designator c = ?0 thru 85 c blank = 0 thru 70 c
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 225 mc9s08rc/rd/re/rg d.2.1 28-pin soic package drawing a1 case 751f-05 issue f date 05/27/97 1 15 14 28 b s a m 0.025 b s c m 0.25 b m seating plane a notes: 1. dimensions are in millimeters. 2. interpret dimensions and tolerances per asme y14.5m, 1994. 3. dimensions d and e do not include mold protrusions. 4. maximum mold protrusion 0.015 per side. 5. dimension b does not include dambar pro- trusion. allowable dambar protrusion shall be 0.13 total in excess of b dimension at maximum material condition. dim min max millimeters a 2.35 2.65 a1 0.13 0.29 b 0.35 0.49 c 0.23 0.32 d 17.80 18.05 e 7.40 7.60 e 1.27 bsc h 10.05 10.55 l 0.41 0.90 q 08 __ l q c pin 1 ident a b d e h e 0.10 c
ordering information and mechanical drawings mc9s08rc/rd/re/rg 226 freescale semiconductor d.2.2 28-pin pdip package drawing
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 227 mc9s08rc/rd/re/rg d.2.3 32-pin lqfp package drawing case 873a-02 issue a date 12/16/93 detail y a s1 v b 1 8 9 17 25 32 ae ae p detail y base n j d f metal section ae-ae g seating plane r q w k x 0.250 (0.010) gauge plane e c h detail ad notes: 1. dimensioning and tolerancing per ansi y14.5m, 1982. 2. controlling dimension: millimeter. 3. datum plane -ab- is located at bottom of lead and is coincident with the lead where the lead exits the plastic body at the bottom of the parting line. 4. datums -t-, -u-, and -z- to be determined at datum plane -ab-. 5. dimensions s and v to be determined at seating plane -ac-. 6. dimensions a and b do not include mold protrusion. allowable protrusion is 0.250 (0.010) per side. dimensions a and b do include mold mismatch and are determined at datum plane -ab-. 7. dimension d does not include dambar protrusion. dambar protrusion shall not cause the d dimension to exceed 0.520 (0.020). 8. minimum solder plate thickness shall be 0.0076 (0.0003). 9. exact shape of each corner may vary from depiction. dim a min max min max inches 7.000 bsc 0.276 bsc millimeters b 7.000 bsc 0.276 bsc c 1.400 1.600 0.055 0.063 d 0.300 0.450 0.012 0.018 e 1.350 1.450 0.053 0.057 f 0.300 0.400 0.012 0.016 g 0.800 bsc 0.031 bsc h 0.050 0.150 0.002 0.006 j 0.090 0.200 0.004 0.008 k 0.500 0.700 0.020 0.028 m 12 ref 12 ref n 0.090 0.160 0.004 0.006 p 0.400 bsc 0.016 bsc q 1515 r 0.150 0.250 0.006 0.010 v 9.000 bsc 0.354 bsc v1 4.500 bsc 0.177 bsc __ ____ detail ad a1 b1 v1 4x s 4x b1 3.500 bsc 0.138 bsc a1 3.500 bsc 0.138 bsc s 9.000 bsc 0.354 bsc s1 4.500 bsc 0.177 bsc w 0.200 ref 0.008 ref x 1.000 ref 0.039 ref 9 -t- -z- -u- t- u 0.20 (0.008) z ac t- u 0.20 (0.008) z ab 0.10 (0.004) ac -ac- -ab- m 8x -t-, -u-, -z- t- u m 0.20 (0.008) z ac
ordering information and mechanical drawings mc9s08rc/rd/re/rg 228 freescale semiconductor d.2.4 44-pin lqfp package drawing 44 1 34 33 11 12 22 23 view y -l- -n- ( 2) c view aa (k) e (z) view aa case 824d-02 issue a date 08/09/95 f u section ab-ab j d base metal plating ab ab view y q s l-m m 0.20 (0.008) n s t 2x r -m- 3x b1 v1 b l-m 0.2 (0.008) t v a1 s1 a s n l-m 0.2 (0.008) hn 4x 4x 11 tips -t- -h- q 4x ( 3) q 4x 0.1 (0.004) t q 1 r1 (w) c2 c1 s 0.05 (0.002) 0.25 (0.010) gage plane 40x g -x- x=l, m, n c l rotated 90 clockwise dim min max min max inches millimeters a 10.00 bsc 0.394 bsc a1 5.00 bsc 0.197 bsc b 10.00 bsc 0.394 bsc b2 5.00 bsc 0.197 bsc c --- 1.60 --- 0.063 c1 0.05 0.15 0.002 0.006 c2 1.35 1.45 0.053 0.057 d 0.30 0.45 0.012 0.018 e 0.45 0.75 0.018 0.030 f 0.30 0.40 0.012 0.016 g 0.80 bsc 0.031 bsc j 0.09 0.20 0.004 0.008 k 0.50 ref 0.020 ref r1 0.09 0.20 0.004 0.008 s 12.00 bsc 0.472 bsc s1 6.00 bsc 0.236 bsc u 0.09 0.16 0.004 0.006 v 12.00 bsc 0.472 bsc v1 6.00 bsc 0.236 bsc w 0.20 ref 0.008 ref z 1.00 ref 0.039 ref q 0707 q 0 --- 0 --- q 12 ref 12 ref q 12 ref 12 ref notes: 1. dimensioning and tolerancing per ansi y14.5m, 1982. 2. controlling dimension: millimeter. 3. datum plane -h- is located at bottom of lead and is coincident with the lead where the lead exits the plastic body at the bottom of the parting line. 4. datums -l-, -m- and -n- to be determined at datum plane -h-. 5. dimensions s and v to be determined at seating plane -t-. 6. dimensions a and b do not include mold protrusion. allowable protrusion is 0.25 (0.010) per side. dimensions a and b do include mold mismatch and are determined at datum plane -h-. 7. dimension d does not include dambar protrusion. dambar protrusion shall not cause the d dimension to exceed 0.53 (0.021). minimum space between protrusion and adjacent lead or protrusion 0.07 (0.003). 1 2 3 seating plane
soc guide ?MC9S08RG60/d rev 1.10 freescale semiconductor 229 mc9s08rc/rd/re/rg soc guide end sheet need need more than 13 words type on blank page or will turn page landscape in pdf file?? turned white so this would not show up on customer page.
mc9s08rc/rd/re/rg 230 freescale semiconductor final page of 230 pages

MC9S08RG60/d rev 1.10 how to reach us: usa/europe/locations not listed: freescale semiconductor literature distribution p.o. box 5405, denver, colorado 80217 1-800-521-6274 or 480-768-2130 japan: freescale semiconductor japan ltd. sps, technical information center 3-20-1, minami-azabu minato-ku tokyo 106-8573, japan 81-3-3440-3569 asia/paci?: freescale semiconductor h.k. ltd. 2 dai king street tai po industrial estate tai po, n.t. hong kong 852-26668334 learn more: for more information about freescale semiconductor products, please visit http://www.freescale.com information in this document is provided solely to enable system and software implementers to use freescale semiconductor products. there are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. freescale semiconductor reserves the right to make changes without further notice to any products herein. freescale semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does freescale semiconductor assume any liability arising out of the application or use of any product or circuit, and speci?ally disclaims any and all liability, including without limitation consequential or incidental damages. typical parameters which may be provided in freescale semiconductor data sheets and/or speci?ations can and do vary in different applications and actual performance may vary over time. all operating parameters, including ?ypicals must be validated for each customer application by customers technical experts. freescale semiconductor does not convey any license under its patent rights nor the rights of others. freescale semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the freescale semiconductor product could create a situation where personal injury or death may occur. should buyer purchase or use freescale semiconductor products for any such unintended or unauthorized application, buyer shall indemnify and hold freescale semiconductor and its of?ers, employees, subsidiaries, af?iates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that freescale semiconductor was negligent regarding the design or manufacture of the part. freescale and the freescale logo are trademarks of freescale semiconductor, inc. all other product or service names are the property of their respective owners. ?freescale semiconductor, inc. 2004. all rights reserved.


▲Up To Search▲   

 
Price & Availability of MC9S08RG60

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X